你好呀
我正在处理一个乳胶文件,其中显示toc
在一个multicols
环境中,有一个自定义的“部分类似”元素,sobpart
我想打破两列以在单列中显示它的行,这就是我目前所拥有的
\documentclass{article}
\usepackage{titlesec}
\usepackage{multicol}
% % Redefinition of ```\theHpart```
% \renewcommand\theHpart{\theHsobpart.\arabic{part}}
% sobpart
\newcounter{sobpart}
\renewcommand\thesobpart{\Roman{sobpart}}
\newcommand\sobpart[1]{
% reset inner counter
\setcounter{part}{0}
\setcounter{section}{0}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
% add sobpart line
\refstepcounter{sobpart}
\part*{\thesobpart\hspace{1em}--\hspace{1em}#1}
% % add to toc (old)
% \addcontentsline{toc}{part}{
% \end{multicols} %% PW wrong place, see above
% % \begin{multicols}{2} %% PW wrong place, see below
% \thesobpart\hspace{1em}--\hspace{1em}#1
% % ]
% }
% add to toc (Peter's suggestion)
\addtocontents{toc}{\end{multicols}}
\addcontentsline{toc}{part}{\thesobpart\hspace{1em}--\hspace{1em}#1}
\addtocontents{toc}{\begin{multicols}{2}}
}
\begin{document}
% Table of Contents
\renewcommand{\contentsname}{} % remove title
\begin{multicols}{2}[\section*{Content}]
\tableofcontents
\end{multicols}
\part{part0.1}
\sobpart{sobpart1}
\part{part1.1}
\end{document}
添加到目录(旧)
我的想法是插入一个end/begin
multicols
但每当我注释掉该修改时我都会收到以下错误
./.build/test.toc:2: Missing } inserted.
<inserted text>
}
l.2 ... I\hspace {1em}--\hspace {1em}sobpart1 ] }{1}
{}%
./.build/test.toc:2: Extra }, or forgotten \endgroup.
\l@part ...umwidth {\hss #2\kern -\p@ \kern \p@ }}
\par \nobreak \if@compatib...
l.2 ... I\hspace {1em}--\hspace {1em}sobpart1 ] }{1}
{}%
)
./test.tex:33: Missing } inserted.
<inserted text>
}
l.33 \tableofcontents
./test.tex:34: Extra }, or forgotten \endgroup.
\endmulticols ...le@items \color@endgroup \egroup
\balance@columns \return@n...
l.34 \end{multicols}
编辑 1:重新定义\theHpart
尝试修改时theHpart
出现以下错误
./test.tex:6: LaTeX Error: Command \theHpart undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.6 \renewcommand\theHpart
{\theHsobpart.\arabic{part}}
theHpart
编辑 1:添加了 Peter 的建议和重新定义命令的建议
答案1
您将multicols
环境代码添加到了 ToC 的错误位置。
% multicoltocprob.tex SE 622645
\documentclass{article}
\usepackage{multicol}
% sobpart
\newcounter{sobpart}
\renewcommand\thesobpart{\Roman{sobpart}}
\newcommand\sobpart[1]{
% reset inner counter
\setcounter{part}{0}
\setcounter{section}{0}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
% add sobpart line
\refstepcounter{sobpart}
\part*{\thesobpart\hspace{1em}--\hspace{1em}#1}
% add to toc
\addtocontents{toc}{\end{multicols}}
\addcontentsline{toc}{part}{
% \end{multicols} %% PW wrong place, see above
% \begin{multicols}{2} %% PW wrong place, see below
\thesobpart\hspace{1em}--\hspace{1em}#1
% ]
}
\addtocontents{toc}{\begin{multicols}{2}}
}
\begin{document}
% Table of Contents
\renewcommand{\contentsname}{} % remove title
\begin{multicols}{2}[\section*{Content}]
\tableofcontents
\end{multicols}
\part{part0.1}
\sobpart{sobpart1}
\part{part1.1}
\end{document}
但是,由于某种原因,第二个\part
没有出现在目录中。我将把这个问题留给你或其他人来解决。
编辑添加 *.toc 文件
\contentsline {part}{I\hspace {1em}part0.1}{1}{}%
\end {multicols}
\contentsline {part}{ I\hspace {1em}--\hspace {1em}sobpart1 }{1}{}%
\begin {multicols}{2}
\contentsline {part}{I\hspace {1em}part1.1}{1}{}%