![自动调整 paracol(或 minipage、tabularx 等)中的左列宽度以适合未换行的文本](https://linux22.com/image/416700/%E8%87%AA%E5%8A%A8%E8%B0%83%E6%95%B4%20paracol%EF%BC%88%E6%88%96%20minipage%E3%80%81tabularx%20%E7%AD%89%EF%BC%89%E4%B8%AD%E7%9A%84%E5%B7%A6%E5%88%97%E5%AE%BD%E5%BA%A6%E4%BB%A5%E9%80%82%E5%90%88%E6%9C%AA%E6%8D%A2%E8%A1%8C%E7%9A%84%E6%96%87%E6%9C%AC.png)
我对 LaTeX 还很陌生。在 MWE 中,我需要标题和额外信息文本永不换行。我需要根据需要换行小细节,同时充分利用空间。我认为如果左列宽度自动设置为未换行的文本内容宽度,那么一切都应该按预期工作。
实际文本将由 Python 脚本定期生成,因此,如果可能的话,我需要它在没有人工干预的情况下工作。并且还可以与目录中的正常分段等配合使用。
我并没有完全依赖 paracol,但与我尝试过的其他解决方案(例如 tabularx 等)相比,我更接近所需的结果。我在网上找到的一些解决方案似乎有效直到我包含了 \section 然后中断。
我觉得这应该比我做的要容易?
\documentclass[12pt,letterpaper]{scrartcl}
\usepackage[english]{babel}
\usepackage{paracol}
\begin{document}
\setlength{\columnseprule}{0.4pt}
% set 3.9in automatically, rather than manually
\setcolumnwidth{3.9in, \fill}
\begin{paracol}{2}
\section{Header That Goes Here (Longer)}
{\bfseries\large Extra info Goes Here}
\switchcolumn
\raggedleft
{\footnotesize Small details go here}
\end{paracol}
\clearpage
\setlength{\columnseprule}{0.4pt}
% set 4.6in automatically, rather than manually
\setcolumnwidth{4.6in, \fill}
\begin{paracol}{2}
\section{Header That Goes Here}
{\bfseries\large Extra info Goes Here (Sometimes is a bit longer)}
\switchcolumn
\raggedleft
{\footnotesize Small details go here}
\end{paracol}
\clearpage
\setlength{\columnseprule}{0.4pt}
% set 3.9in automatically, rather than manually
\setcolumnwidth{3.9in, \fill}
\begin{paracol}{2}
\section{Header That Goes Here (Longer)}
{\bfseries\large Extra info Goes Here}
\switchcolumn
\raggedleft
{\footnotesize Small details go here, and these are sometimes longer}
\end{paracol}
\end{document}
答案1
您可以使用 tabularx,但左侧文本太长,无法换行......
\documentclass[12pt,letterpaper]{scrartcl}
\usepackage[english]{babel}
\usepackage{tabularx}
\newcommand\zsec[3]{%
\par
\bigskip
\noindent
\begin{tabularx}{\linewidth}{@{}l|>{\raggedleft\arraybackslash}X@{}}%
\large\sffamily\bfseries\refstepcounter{section}\thesection. #1&\\[5pt]
\mbox{\bfseries\large#2}&\footnotesize \vspace*{-30pt} #3\end{tabularx}\par}
\begin{document}
\zsec
{Header That Goes Here (Longer)}
{Extra info Goes Here}
{Small details go here}
\zsec
{Header That Goes Here}
{Extra info Goes Here (Sometimes is a bit longer)}
{Small details go here}
\zsec
{Header That Goes Here (Longer)}
{Extra info Goes Here}
{Small details go here, and these are sometimes longer}
\end{document}