三列布局

三列布局

我的老板要求报告采用三列布局:

  • 第 1 列:各节(小节、小小节……)下的所有标题。标题文本应在第一列中断。
  • 第 2 列:正文
  • 第 3 列:参考文献、备注等,此处内容应与正文对应行对齐

我对我的第一稿不太满意:

\documentclass[11pt,a4paper,numbers=noenddot]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[left=2cm, right=1cm]{geometry}

\usepackage{paracol}
\setcolumnwidth{10pt,60pt,10pt}
\usepackage{lipsum}

\begin{document}

\begin{paracol}{3}[\section{\underline{SECTION I - The Project Statement}}]
    \switchcolumn[0]
    \subsection{Subsection1}
    \switchcolumn[1]
    \sloppy
    \lipsum[1]
    \switchcolumn[2]
    see \texttt{www.example.com/example}

    \switchcolumn[1]*
    \sloppy
    \lipsum[2]
    \switchcolumn[2]
    see \texttt{Mayer et. al.}  
\end{paracol}

\end{document}

主要问题:

  • 我通过反复试验确定了列宽。如果某个子节标题太长,布局就会中断
  • 我不能使用\autocite

编辑:我习惯引用\autocite在文档末尾引用并列出参考文献。是否可以保留此工作流程,并在文档第三列中列出参考文献,紧邻其在正文中的出现位置?

你有什么建议吗?

答案1

我建议不要使用paracol,而是设置几何形状,使主体宽度稍小,标题打印在左边距,参考文献、备注等通过以下方式放入右边距marginnote

\documentclass[11pt,a4paper,numbers=noenddot]{scrartcl}

\usepackage[english]{babel}
\usepackage{marginnote}
\usepackage{geometry}

% setup the width for the columns
\newlength\leftcolumn
\newlength\rightcolumn
\newlength\leftcolumnsep
\newlength\rightcolumnsep
\setlength\leftcolumn{4cm}
\setlength\rightcolumn{2.5cm}
\setlength\leftcolumnsep{10pt}
\setlength\rightcolumnsep{\leftcolumnsep}
% store the width for all three columns in \textwidth
\setlength\textwidth{18cm}

% reduce the text width by what is needed for the other columns
\makeatletter
\@tempdima\textwidth
\advance\@tempdima-\leftcolumn
\advance\@tempdima-\leftcolumnsep
\advance\@tempdima-\rightcolumn
\advance\@tempdima-\rightcolumnsep
\ifdim\@tempdima>0pt
  % this is an idiomatic way to set the new width, it assumes the default
  % hratio=1:1 of geometry in onesided mode
  \geometry
    {marginparwidth=\rightcolumn,marginparsep=\rightcolumnsep,width=\@tempdima}
\else
  \GenericError
    {}{Fatal error: Negative \string\textwidth}
    {Make the left and right column smaller}{}%
  \stop
\fi
\newcommand\intoleftcolumn[1]
  {%
    % it is assumed that \intoleftcolumn is always called where a `\par` can
    % appear
    %\par
    \noindent
    \smash{\llap{\parbox[t]{\leftcolumn}{#1}\hskip\leftcolumnsep}}%
  }
\newcommand\intorightcolumn[1]
  {%
    % just use \marginnote for this
    \marginnote{#1}%
  }
\let\sectionlinesformat@orig\sectionlinesformat
\renewcommand\sectionlinesformat[4]
  {%
    \ifstr{#1}{section}{\sectionlinesformat@orig{#1}{#2}{#3}{#4}}%
      {\intoleftcolumn{\sectionlinesformat@orig{#1}{#2}{#3}{#4}}}%
  }
\RedeclareSectionCommand[afterskip=-\baselineskip,runin=false]{subsection}
\RedeclareSectionCommand[afterskip=-\baselineskip,runin=false]{subsubsection}
\makeatother

\usepackage{duckuments} % interesting dummy text

% should be loaded at the end of the preamble
\usepackage[]{hyperref}

\begin{document}
\section{This is a section}
\blindduck
\subsection{This is a subsection\label{sec:sub}}
\blindduck
\subsubsection{This is a subsubsection}
\intorightcolumn{As already shown in \autoref{sec:sub}}
\blindduck
\end{document}

在此处输入图片描述

编辑:自从莱安德里斯指出我弄错了\section,这个编辑确实将它们与左列左对齐,它们可以占据所有三列的总宽度(加上分隔符):


\documentclass[11pt,a4paper,numbers=noenddot]{scrartcl}

\usepackage[english]{babel}
\usepackage{marginnote}
\usepackage{geometry}

% setup the width for the columns
\newlength\leftcolumn
\newlength\rightcolumn
\newlength\leftcolumnsep
\newlength\rightcolumnsep
\newlength\totalcolumnswidth
\setlength\leftcolumn{4cm}
\setlength\rightcolumn{2.5cm}
\setlength\leftcolumnsep{10pt}
\setlength\rightcolumnsep{\leftcolumnsep}
% width for all three columns (this indirectly sets the main columns width)
\setlength\totalcolumnswidth{18cm}

% reduce the text width by what is needed for the other columns
\makeatletter
\@tempdima\totalcolumnswidth
\advance\@tempdima-\leftcolumn
\advance\@tempdima-\leftcolumnsep
\advance\@tempdima-\rightcolumn
\advance\@tempdima-\rightcolumnsep
\ifdim\@tempdima>0pt
  % this is an idiomatic way to set the new width, it assumes the default
  % hratio=1:1 of geometry in onesided mode
  \geometry
    {marginparwidth=\rightcolumn,marginparsep=\rightcolumnsep,width=\@tempdima}
\else
  \GenericError
    {}{Fatal error: Negative \string\textwidth}
    {Make the left and right column smaller}{}%
  \stop
\fi
\newcommand\intoleftcolumn[1]
  {%
    % it is assumed that \intoleftcolumn is always called where a `\par` can
    % appear
    %\par
    \noindent
    \smash{\llap{\parbox[t]{\leftcolumn}{#1}\hskip\leftcolumnsep}}%
  }
\newcommand\intorightcolumn[1]
  {%
    % just use \marginnote for this
    \marginnote{#1}%
  }
\let\sectionlinesformat@orig\sectionlinesformat
\renewcommand\sectionlinesformat[4]
  {%
    \ifstr{#1}{section}
      {%
        \noindent\hskip-\leftcolumn\hskip-\leftcolumnsep
        \rlap
          {%
            \parbox[t]{\totalcolumnswidth}
              {\sectionlinesformat@orig{#1}{#2}{#3}{#4}}%
          }%
      }%
      {\intoleftcolumn{\sectionlinesformat@orig{#1}{#2}{#3}{#4}}}%
  }
\RedeclareSectionCommand[afterskip=-\baselineskip,runin=false]{subsection}
\RedeclareSectionCommand[afterskip=-\baselineskip,runin=false]{subsubsection}
\makeatother

\usepackage{duckuments} % interesting dummy text

% should be loaded at the end of the preamble
\usepackage[]{hyperref}

\begin{document}
\section{This is a section}
\blindduck
\subsection{This is a subsection\label{sec:sub}}
\blindduck
\subsubsection{This is a subsubsection}
\intorightcolumn{As already shown in \autoref{sec:sub}}
\blindduck
\end{document}

在此处输入图片描述

答案2

也许你对以下布局更满意:

在此处输入图片描述

\documentclass[11pt,a4paper,numbers=noenddot]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[left=2cm, right=1cm]{geometry}

\usepackage{paracol}
\setcolumnwidth{3.5cm,9.1cm,5cm}
\setlength{\columnsep}{0.2cm}
\usepackage{lipsum}

\usepackage[bookmarks=false]{hyperref}

\begin{document}

\begin{paracol}{3}[\section{\underline{SECTION I - The Project Statement}}]
    \switchcolumn[0]
    \subsection{Subsection 1}\label{subsec:first}
    \switchcolumn[1]
    \sloppy
    \lipsum[1]
    \switchcolumn[2] {\raggedright
    see \texttt{www.example.com/example}}

    \switchcolumn[1]*
    \sloppy
    \lipsum[2]
    \switchcolumn[2]{\raggedright
    see \texttt{Mayer et. al.} }
    \switchcolumn[0]*
   \subsection{A longer Subsection with a quite long title}
   \switchcolumn[1]
   \sloppy
   \lipsum[4]
   \switchcolumn[2]{\raggedright
   \texttt{As already shown in \autoref{subsec:first}}}
   \switchcolumn[0]*
   \subsubsection{heading of a subsubsection}
\end{paracol}

\end{document}

与原始布局相比,我所做的更改是:我对第一列和第三列使用了更大的宽度,并且明确指定了列之间的宽度。

我为什么决定更改上述值?让我们看看下面的 MWE,它本质上是您的代码的缩短版本,我只是添加了一些代码来生成彩色线条。红线表示文本宽度,蓝线表示您选择的列的宽度。

在此处输入图片描述

\documentclass[11pt,a4paper,numbers=noenddot]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[left=2cm, right=1cm]{geometry}


\usepackage{paracol}
\setcolumnwidth{10pt,60pt,10pt}

%%%% Colored lines %%%%
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
\setlength{\columnseprule}{0.4pt}
\colseprulecolor{blue}
%%%%               %%%%  

\usepackage{lipsum}

\begin{document}

\begin{paracol}{3}[\section{\underline{SECTION I - The Project Statement}}]
    \switchcolumn[0]
    \subsection{Subsection1}
    \switchcolumn[1]
    \sloppy
    \lipsum[1]
    \switchcolumn[2]
    see \texttt{www.example.com/example}  
\end{paracol}

\end{document}

从上面的示例中可以看出,左列对于其所包含的文本来说太窄了。只有相当大的列间标准宽度 ( \columnsep) 才能防止子部分标题与中间列中的文本重叠。此外,加起来的列宽比文本宽度更宽:

left col + columnsep + middle col + columnsep + right col > textwidth

为了解决这个问题,我重新计算了宽度,如下所示:标准 A4 纸的宽度为 21 厘米。如果我们减去您通过 设置的左和右边距(分别为 2 和 1 厘米)geometry,我们最终会得到 18 厘米的文本宽度,我们可以将其用于该列。这 18 厘米被分成三列,如下所示,其中 0.2 厘米是列之间空白的宽度。

3.5 cm  + 0.2 cm + 9.1 cm  + 0.2 cm + 5 cm = 18 cm

如果我们现在将以下代码块添加到第一个 MWE 中,我们将获得以下结果。由此,我们可以清楚地看到,现在各列彼此不重叠,也不与边距重叠。

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
\setlength{\columnseprule}{0.4pt}
\colseprulecolor{blue}

在此处输入图片描述

答案3

与 Leandaris 的解决方案类似,只是我使用 url 包来分解 url 并测量了小节标题的宽度(大概是最大的)。

最大的问题是它\raggedright不能限制在一列中。注意:如果您希望小节后的第一段缩进,请添加\everypar{}到列序言中。

\documentclass[11pt,a4paper,numbers=noenddot]{scrartcl}
%\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[left=2cm, right=1cm]{geometry}

\usepackage{paracol}
\globalcounter{section}
\globalcounter{subsection}
\begingroup% compute using local registers
  \sbox0{\Large\textbf{{Subsection1}}}%
  \dimen0=\dimexpr \textwidth-2\columnsep-\wd0-\marginparwidth\relax
  \xdef\columnA{\the\wd0}% save as global macros
  \xdef\columnB{\the\dimen0}%
\endgroup

\setcolumnwidth{\columnA,\columnB,\marginparwidth}
\definecolumnpreamble{1}{\sloppy \parindent=\bibindent \rightskip=0pt}% parameters will not reset automatically
\definecolumnpreamble{2}{\parindent=0pt \rightskip=0pt plus 1fil}% \ragggedright

\usepackage{lipsum}
\usepackage{url}

\begin{document}

\begin{paracol}{3}[\section{\underline{SECTION I - The Project Statement}}]
    \switchcolumn[0]
    \subsection{Subsection1}
    \switchcolumn[1]
    \lipsum[1]
    \switchcolumn[2]
    see \url{www.example.com/example}
    \switchcolumn[1]*
    \lipsum[2]
    \switchcolumn[2]
    see \texttt{Mayer et.\ al.}% period not end of sentence
\end{paracol}

\end{document}

演示

相关内容