Text in two columns on the same level

1,098

Just for fun, the following uses tikzpagenodes to align selected locations to multiples of \baselineskip. It uses \vspace*{\fill} at the bottom of each column as a more powerful version of \raggedbottom. Otherwise the y location for the lines would never be the same from one run to the next. It will still take many runs before the alignment can work its way to the bottom of the page.

\RequirePackage{fix-cm}
\documentclass[fontsize=8.5pt,DIV=calc]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{helvet}

\usepackage{geometry}
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm} 

\renewcommand{\familydefault}{\sfdefault}
\usepackage{multicol} 
\usepackage{xcolor}

\usepackage{mdframed}   
\usepackage{paralist}    

\setlength\parindent{0pt}
\setlength\columnsep{5mm}

\renewcommand\familydefault{\sfdefault}
\renewcommand{\labelitemi}{\textcolor{black!60}{\raisebox{0.5mm}{\rule{1.8mm}{1.8mm}}}}
\newcommand{\zitiert}[1]{\flqq{#1}\frqq}

\usepackage{enumitem}
\setitemize{leftmargin=*}

%FOR GREY RECTANGLE
\addtokomafont{section}{\large}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}
    {\setlength\fboxsep{1.75mm}%
      \colorbox{black!15}{\raisebox{0pt}[\height][0pt]{%
        \parbox[b]{\dimexpr\linewidth-2\fboxsep\relax}{%
          \raggedsection\@hangfrom{\hskip#2#3}{#4}%
    }}}}
    {\@hangfrom{\hskip#2#3}{#4}}%
}
\renewcommand\sectionformat{%
  \makebox[10mm][r]{\thesection\autodot\hspace{5mm}}
}
\makeatother

\usepackage{tikzpagenodes}
\newlength{\baselineoffset}

\newcommand{\resetbase}% put baseline a multiple of \baselineskip below top of page
  {\strut\tikz[remember picture, overlay]{\pgfextracty{\baselineoffset}%
    {\pgfpointdiff{\pgfpointorigin}{\pgfpointanchor{current page text area}{north}}}
    \global\baselineoffset=\baselineoffset}%
  \advance\baselineoffset by \dimexpr \baselineskip-\topskip\relax
  \loop\ifdim\baselineoffset>\baselineskip
    \advance\baselineoffset by -\baselineskip
  \repeat
  \vspace{-\baselineoffset}\par}

%\let\resetbase\relax

\usepackage{lipsum}

\begin{document}
\begin{multicols}{2}
\resetbase Some random text....
\subsection{One}

\section{Two}

\subsection{Three}

\resetbase\lipsum[1]
\subsection{Four}

\resetbase\lipsum[1]

\subsection{Five}
\resetbase\lipsum[1]
\vspace*{\fill}\columnbreak
\subsection{Six}

\resetbase\lipsum[1]
With an enumeration:
\begin{compactenum}[a)]
\item \resetbase\lipsum[1]
\item \resetbase\lipsum[1]

\end{compactenum}
\ \\
\resetbase\lipsum[1]
\vspace*{\fill}
\end{multicols}
\end{document}
Share:
1,098

Related videos on Youtube

GuestUser
Author by

GuestUser

Updated on August 01, 2022

Comments

  • GuestUser
    GuestUser over 1 year

    I have a code with sections, subsections, enumerations in two-columns style:

    \RequirePackage{fix-cm}
    \documentclass[fontsize=8.5pt,DIV=calc]{scrbook}
    \usepackage[T1]{fontenc}
    \usepackage[ngerman]{babel}
    \usepackage[utf8]{inputenc}
    \usepackage{helvet}
    
    \usepackage{geometry}
    \geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm} 
    
    \renewcommand{\familydefault}{\sfdefault}
    \usepackage{multicol} 
    \usepackage{xcolor}
    
    \usepackage{mdframed}   
    \usepackage{paralist}    
    
    \setlength\parindent{0pt}
    \setlength\columnsep{5mm}
    
    \renewcommand\familydefault{\sfdefault}
    \renewcommand{\labelitemi}{\textcolor{black!60}{\raisebox{0.5mm}{\rule{1.8mm}{1.8mm}}}}
    \newcommand{\zitiert}[1]{\flqq{#1}\frqq}
    
    \usepackage{enumitem}
    \setitemize{leftmargin=*}
    
    %FOR GREY RECTANGLE
    \addtokomafont{section}{\large}
    \makeatletter
    \renewcommand\sectionlinesformat[4]{%
      \ifstr{#1}{section}
        {\setlength\fboxsep{1.75mm}%
          \colorbox{black!15}{\raisebox{0pt}[\height][0pt]{%
            \parbox[b]{\dimexpr\linewidth-2\fboxsep\relax}{%
              \raggedsection\@hangfrom{\hskip#2#3}{#4}%
        }}}}
        {\@hangfrom{\hskip#2#3}{#4}}%
    }
    \renewcommand\sectionformat{%
      \makebox[10mm][r]{\thesection\autodot\hspace{5mm}}
    }
    \makeatother
    
    \usepackage{lipsum}
    
    \begin{document}
    \begin{multicols}{2}
    Some random text....
    \subsection{One}
    
    \section{Two}
    
    \subsection{Three}
    
    \lipsum[1]
    \subsection{Four}
    
    \lipsum[1]
    \subsection{Five}
    
    \lipsum[1]
    \subsection{Six}
    
    \lipsum[1]
    With an enumeration:
    \begin{compactenum}[a)]
    \item \lipsum[1]
    \item \lipsum[1]
    
    \end{compactenum}
    \ \\
    \lipsum[1]
    \end{multicols}
    \end{document}
    

    Unfortunately, the rows of the two columns are not on the same "level" (as you can see in the picture below - marked with the red line). enter image description here

    Is there a way (general) way to solve this problem?