![并排放置内容:minipage-columns 不能打破页面,paracol-columns 会引入过多的水平空间](https://linux22.com/image/432757/%E5%B9%B6%E6%8E%92%E6%94%BE%E7%BD%AE%E5%86%85%E5%AE%B9%EF%BC%9Aminipage-columns%20%E4%B8%8D%E8%83%BD%E6%89%93%E7%A0%B4%E9%A1%B5%E9%9D%A2%EF%BC%8Cparacol-columns%20%E4%BC%9A%E5%BC%95%E5%85%A5%E8%BF%87%E5%A4%9A%E7%9A%84%E6%B0%B4%E5%B9%B3%E7%A9%BA%E9%97%B4.png)
我想将项目并排放置在两列布局中,中间留出一些空间(想象三列,中间一列是空的)。我想定义一个环境,为每个条目传递左列和右列的内容。到目前为止,我使用了并排的minipage
(见下面的“版本 1”),它工作得很好,但不适用于较长的条目(见下文,当第二个条目移动到第 2 页时,第一页上剩下很多垂直空间)。然后我发现paracol
。我再次定义了一个环境(见下面的“版本 2”),但正如您所见(在生成的 PDF 的第 3 页和第 4 页),引入了一些水平空间(为什么?)。左列中的条目不再完全右对齐,右列中的条目也不再完全左对齐。如何解决这个问题?
(如果有更好的解决方案(不使用 paracol),我也很想知道,因为即使paracol
使用包的功能,我也在使用脚注时遇到了问题。我需要的是列中的全部功能(因为我也在那里打印参考资料和其他东西)。此外,在我的例子中,列的宽度必然不同(我认为这排除了这种可能性multicol
)并且可以扩展到页面)
\documentclass{scrartcl}
\usepackage{paracol}
\usepackage{calc}
\usepackage{titlesec}
\usepackage{blindtext}
\usepackage{tikz}
% Misc
\parindent0mm% to see better what's going on
\parskip1ex% define paragraph skip
% Define fractions of \textwidth for the columns (fractions are more suitable for \columnratio below)
\newcommand{\lcol}{0.24}% fraction of the left column
\newcommand{\mcol}{0.04}% horizontal space between the two columns
\newcommand{\rcol}{0.72}% fraction of the right column
% Bar for section headings (to see better what's going on)
\newcommand*{\sectionbar}{\raisebox{0.5ex}{\tikz\fill(0mm,0ex)rectangle+(\lcol\textwidth,0.5ex);}}
\titleformat{\section}{\Large\sffamily}{\sectionbar}{\mcol\textwidth}{}
\titlespacing{\section}{0mm}{1.4ex plus 1ex minus .2ex}{0ex plus .2ex}
% Version 1: minipage approach (works well but fails over pagebreaks)
\newcommand*{\entrymini}[2]{% arguments = (left entry, right entry)
\par
\begin{minipage}[t]{\lcol\textwidth}%
{\raggedleft #1\par}%
\end{minipage}%
\hfill%
\begin{minipage}[t]{\rcol\textwidth}%
#2%
\end{minipage}%
\par
}
% Version 2: paracol approach (introduces spurious space in the middle)
% Define an environment for switching to the 3-column layout
\newcommand*{\entrypara}[2]{% arguments = (left entry, right entry)
\columnratio{\lcol,\mcol,\rcol}
\begin{paracol}{3}
{\raggedleft #1\par}%
\switchcolumn%
\switchcolumn%
#2%
\end{paracol}
}
\begin{document}
This is the solution with minipages, which works for many entries except if there are page breaks:
\section{With minipages}
\entrymini{April 01, 2021}{\blindtext[1]}
\entrymini{April 29, 2021}{\blindtext[3]}
\clearpage\bigskip
This is the solution with paracol (which neither aligns the left column properly
on the right, nor aligns the right column properly on the left; where is the additional
horizontal space coming from?):
\section{With paracol}
\entrypara{April 01, 2021}{\blindtext[1]}
\entrypara{April 29, 2021}{\blindtext[3]}
\end{document}
更新(包含各种解决方案)
以下内容结合了paracol
Pieter 在本文评论中指出的解决方案。它还结合了 Pieter 和 Ulrike 指出的两种列表方法(但没有一种方法可以正确地为较长的项目换行)。
\documentclass{scrartcl}
\usepackage{paracol}
\usepackage{calc}
\usepackage{titlesec}
\usepackage{blindtext}
\usepackage{tikz}
\usepackage{enumitem}
% Misc
\parindent0mm% to see better what's going on
\parskip1ex% define paragraph skip
% Define fractions of \textwidth for the columns (fractions are more suitable for \columnratio below)
\newcommand{\lcol}{0.24}% fraction of the left column
\newcommand{\mcol}{0.04}% horizontal space between the two columns
\newcommand{\rcol}{0.72}% fraction of the right column
% Bar for section headings (to see better what's going on)
\newcommand*{\sectionbar}{\raisebox{0.5ex}{\tikz\fill(0mm,0ex)rectangle+(\lcol\textwidth,0.5ex);}}
\titleformat{\section}{\Large\sffamily}{\sectionbar}{\mcol\textwidth}{}
\titlespacing{\section}{0mm}{1.4ex plus 1ex minus .2ex}{0ex plus .2ex}
% Version 1: minipage approach (works well but fails over pagebreaks)
\newcommand*{\entrymini}[2]{% arguments = (left entry, right entry)
\par
\begin{minipage}[t]{\lcol\textwidth}%
{\raggedleft #1\par}%
\end{minipage}%
\hfill%
\begin{minipage}[t]{\rcol\textwidth}%
#2%
\end{minipage}%
\par
}
% Version 2: paracol approach
\setlength{\columnsep}{0pt}% => fixes space-problem
\newcommand*{\entrypara}[2]{% arguments = (left entry, right entry)
\columnratio{\lcol,\mcol,\rcol}
\begin{paracol}{3}
{\raggedleft #1\par}%
\switchcolumn%
\switchcolumn%
#2%
\end{paracol}
}
% Version 3: With lists (as suggested by Pieter and Ulrike)
\newcommand*{\entrylist}[2]{%
\begin{list}{}{%
\setlength{\labelsep}{\mcol\textwidth}%
\setlength{\labelwidth}{\lcol\textwidth}%
\setlength{\leftmargin}{\dimexpr\labelwidth+\labelsep}%
}%
\item[#1]#2\end{list}
}
% Version 4: With enumitem
\newcommand*{\entryitem}[2]{
\begin{itemize}[align=right, leftmargin=!, labelwidth=\lcol\textwidth, labelsep=\mcol\textwidth]
\item[#1] #2
\end{itemize}
}
\begin{document}
\section{With minipages}
\entrymini{April 01, 2021}{\blindtext[1]}
\entrymini{April 29, 2021}{\blindtext[3]}
\entrymini{Here is some longer text that should break over lines and be right-aligned}{\blindtext[1]}
\clearpage
\section{With paracol}
\entrypara{April 01, 2021}{\blindtext[1]}
\entrypara{April 29, 2021}{\blindtext[3]}
\entrypara{Here is some longer text that should break over lines and be right-aligned}{\blindtext[1]}
\clearpage
\section{With lists}
\entrylist{April 01, 2021}{\blindtext[1]}
\entrylist{April 29, 2021}{\blindtext[3]}
\entrylist{Here is some longer text that should break over lines and be right-aligned}{\blindtext[1]}
\clearpage
\section{With enumitem}
\entryitem{April 01, 2021}{\blindtext[1]}
\entryitem{April 29, 2021}{\blindtext[3]}
\entryitem{Here is some longer text that should break over lines and be right-aligned}{\blindtext[1]}
\entryitem{Here is a hack}{}
\entryitem{... not very elegant but works}{\vspace{-2mm}}
\entryitem{}{\vspace{-13mm}\blindtext[1]}
\entryitem{{\smash{\parbox[t]{\lcol\textwidth}{\raggedleft Here is some longer text that should break over lines and be right-aligned}}}}{\blindtext[1]}% here is a nicer version for longer labels -- but Pieter's solution (see the accepted solution) is even more elegant in this regard.
\clearpage
\end{document}
答案1
list
这是我在第二条评论中建议的环境解决方案。编辑:允许多行左列。但是该条目中不会有分页符。
\newcommand*{\entrylist}[2]{%
\begin{list}{}{%
\setlength{\labelsep}{\mcol\textwidth}%
\setlength{\labelwidth}{\lcol\textwidth}%
\setlength{\leftmargin}{\dimexpr\labelwidth+\labelsep}%
}%
\item[{\parbox[t][\baselineskip]{\labelwidth}{\raggedleft#1}}]#2\end{list}
}
\section{With list}
\entrylist{April 01, 2021}{\blindtext[1]}
\entrylist{April 29, 2021}{\blindtext[3]}