就像问的那样这里,我希望多行条目的所有行根据标题缩进,如下所示:
我怎样才能获得预期的结果,最好不使用其他文档类?保留这些包也是一个不错的选择,但如果titletoc
不支持这种排版,其他包也可以!
分数维:
\documentclass[10pt,twoside,a4paper]{article}
\usepackage{titlesec,titletoc}
\renewcommand*\contentsname{Quick Answers}
\titleformat{\section}{\Large\bfseries}{
\ifnum\thesection<10 Q 0\thesection
\else Q \thesection \fi
}{0.5em}{}
\titlecontents{section}[0.5em]{}{
\large \textbf{Q\contentsmargin{20pt}
\ifnum\thecontentslabel<10 0\else\fi
\thecontentslabel\enspace} }
{\contentsmargin{20pt}\normalfont}{\titlerule*[1mm]{ $\cdot$}\contentspage}
[\addvspace{-2pt}]
\begin{document}
\tableofcontents
\section{Answer 1}
\section{Answer 2-a \\ Answer 2-b}
\end{document}
答案1
用于\contentslabel[<format>]{<space>}
内容标签并添加<space>
到第一个可选参数中的缩进。请注意,您还必须避免使用虚假空格。
\documentclass[10pt,twoside,a4paper]{article}
\usepackage{titlesec,titletoc}
\renewcommand*\contentsname{Quick Answers}
\titleformat{\section}{\Large\bfseries}{% <- comment the line end to avoid a spurious space
\ifnum\thesection<10 Q 0\thesection
\else Q \thesection \fi
}{0.5em}{}
\titlecontents{section}
[4.5em]% indent (.5em) + label width (4em)
{\contentsmargin{20pt}}
{% <- comment the line end to avoid a spurious space
\contentslabel[\large\textbf{Q
\ifnum\thecontentslabel<10 0\else\fi
\thecontentslabel\enspace}]{4em}% <- comment the line end to avoid a spurious space
}
{\normalfont}{\titlerule*[1mm]{ $\cdot$}\contentspage}
[\addvspace{2pt}]% <- changed
\begin{document}
\tableofcontents
\section{Answer 1}
\section{Answer 2-a \\ Answer 2-b}
\end{document}
答案2
我的做法与 esdd 略有不同,以下是我的解决方案:
\documentclass[10pt,twoside,a4paper]{article}
\usepackage{titlesec,titletoc}
\renewcommand*\contentsname{Quick Answers}
\titleformat{\section}{\Large\bfseries}{% <-- don't forget the percent sign!
\ifnum\thesection<10 Q 0\thesection
\else Q \thesection
\fi
}{0.5em}{}
\newlength{\contentslabelwidth}
\setlength{\contentslabelwidth}{3.5em}
\newcommand*{\myprintcontentslabel}{%
\begingroup
\normalfont\large\bfseries
Q\ifnum\thecontentslabel<10 0\else\fi % always two figures
\thecontentslabel
\endgroup
}
\titlecontents{section}[\contentslabelwidth]{}{% <-- don't forget!
\contentsmargin{20pt}%
\llap{\makebox[\contentslabelwidth][l]{\myprintcontentslabel}}}%
{\contentsmargin{20pt}\normalfont}%
{\titlerule*[1mm]{ $\cdot$}\contentspage}
[] % I removed the \addvspace{-2pt} here: it made the lines way too close to
% each other.
\begin{document}
\tableofcontents
\section{Answer 1}
\section{Answer 2-a\\ Answer 2-b}
\end{document}
您有几个虚假的空间,要小心这些(参见代码中的注释)!