我有一个包含两列样式的章节、小节和枚举的代码:
\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}
不幸的是,两列的行并不在同一个“级别”上(如下图所示 - 用红线标记)。
有没有办法(通用)解决这个问题?
答案1
只是为了好玩,下面使用tikzpagenodes
将选定位置与 的倍数对齐\baselineskip
。它\vspace*{\fill}
在每列底部使用 作为 的更强大版本\raggedbottom
。否则,线条的 y 位置在一次运行和下一次运行之间永远不会相同。在对齐可以到达页面底部之前,仍需要多次运行。
\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}