在目录中添加多列

在目录中添加多列

是否可以将多列环境中的节/小节的列添加到目录中?

目前的目录如下

1. Headline 1 ......... 1 % Shows only the page
2. Headline 2 ......... 1
3. Headline 3 ......... 1

但我希望它看起来像这样

1. Headline 1 ......... 1.1 % <page>.<column>
2. Headline 2 ......... 1.3
3. Headline 3 ......... 1.5

这是一个最小的例子,需要进行扩展:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, landscape, margin=3cm]{geometry}
\usepackage{lipsum} 
\usepackage{multicol}

\begin{document}
\begin{multicols*}{5}

\tableofcontents
\section{Headline 1}
\lipsum[1-3]

\section{Headline 2}
\lipsum[4-6]

\section{Headline 3}
\end{multicols*}

\end{document}

答案1

下面的代码可以满足您的要求。需要运行几次(3)才能显示所有正确信息。该选项colaction对于命令\docolaction和补丁的运行必不可少。

任意列数的新答案

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum} 
\usepackage[colaction]{multicol}
\usepackage[left=1cm,right=1cm,top=1cm,bottom=1cm]{geometry}
\usepackage{etoolbox}

\makeatletter
\newcounter{brnk@col@count}
\renewcommand*\addcontentsline[3]
  {%
    \addtocontents{#1}
      {%
        \protect\contentsline{#2}{#3}
          {\thepage\ifnum\doublecol@number>0\relax.\string\brnk@cur@col\fi}%
      }%
  }
\def\brnk@patch@last
  {%
    \stepcounter{brnk@col@count}%
    \protected@write\@auxout{}%
      {%
        \string\@writefile{toc}%
          {\string\def\string\brnk@cur@col{\arabic{brnk@col@count}}}%
      }%
  }
\def\brnk@patch@else
  {%
    \ifmc@firstcol
      \setcounter{brnk@col@count}{0}%
    \fi
    \brnk@patch@last
  }
\def\brnk@patch@error
  {%
    \GenericError{}
      {Patching of \string\mc@col@status@write\space failed}
      {%
        Make sure `colaction` was set as an option for `multicol`.%
        \MessageBreak
        Else you're screwed, don't use the code provided here.\MessageBreak%
      }
      {No further help available.}%
  }
\pretocmd\mc@lastcol@status@write{\brnk@patch@last}{}{\brnk@patch@error}
\pretocmd\mc@col@status@write{\brnk@patch@else}{}{\brnk@patch@error}
\makeatother

\begin{document}
\begin{multicols*}{5}

\tableofcontents
\section{Headline 1}
\lipsum[1-2]

\section{Headline 2}
\lipsum[3]

\section{Headline 3}
\lipsum[4-7]

\subsection{Subsection 1}
\lipsum[8]
\subsection{Subsection 2}
\lipsum[9]
\end{multicols*}
\section{Headline 4}
\lipsum[5]
\begin{multicols*}{2}
\section{Headline 5}
\lipsum[6]
\end{multicols*}

\end{document}

在此处输入图片描述


原始答案只有 3 列

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum} 
\usepackage[colaction]{multicol}

\makeatletter
\renewcommand*\addcontentsline[3]{%
  \def\brnk@column{}%
  \ifnum\doublecol@number>0
    \docolaction
      [5]
      {\def\brnk@column{.1}}
      {\def\brnk@column{.2}}
      {\def\brnk@column{.3}}%
  \fi
  \addtocontents{#1}{\protect\contentsline{#2}{#3}
    {\thepage\brnk@column}}}
\makeatother

\begin{document}
\begin{multicols*}{3}

\tableofcontents
\section{Headline 1}
\lipsum[1-2]

\section{Headline 2}
\lipsum[3]

\section{Headline 3}
\lipsum[4]
\end{multicols*}
\section{Headline 4}
\lipsum[5]
\begin{multicols*}{2}
\section{Headline 5}
\lipsum[6]
\end{multicols*}

\end{document}

生成的目录:

在此处输入图片描述

相关内容