我将长路径作为章节标题,需要适当的换行符。我不需要连字符或任何换行规则。
\section{Important Paths}
\subsection{trunk/Averylong/Bverylong/Cverylongverylong/Dverylongverylong/Everylong/Fverylong\_file\_Name.txt}
\subsection{trunk/Averylong/Bverylong/Cverylongverylong/Dverylongverylong/Everylong/Fverylong file Name.txt}
我能存档的唯一方法是在每个字符后添加一个 hspace。输出正是我想要的。但这似乎不是一个明智的解决方案。
\subsection{t\hspace{0pt}r\hspace{0pt}u\hspace{0pt}n\hspace{0pt}k\hspace{0pt}/\hspace{0pt}A\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}B\hspace{0pt}v\hspace{0pt}e\hspace{0pt}rvy\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}C\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}D\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}E\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}v\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}F\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt} \hspace{0pt}f\hspace{0pt}i\hspace{0pt}l\hspace{0pt}e\hspace{0pt} \hspace{0pt}N\hspace{0pt}a\hspace{0pt}m\hspace{0pt}e\hspace{0pt}.\hspace{0pt}t\hspace{0pt}x\hspace{0pt}t\hspace{0pt}}
输出为:
1.1 甚至超出了 pdf 的末尾。
我已经创建了一个简单的sharelatex 上的文档。
\documentclass[11pt,a4paper,fleqn]{scrartcl}
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[raggedright]{titlesec}
\usepackage[hidelinks]{hyperref}
\usepackage{xcolor}
% Color definitions
\colorlet{mygray}{gray!30}
% Customize headings
\titleformat{\section}
{\normalfont\sffamily\Large\fontfamily{phv}\selectfont}
{\thesection.}{.5em}{}[{\vspace{.2ex}\titleline{\color{mygray}\titlerule[2pt]}}]
\titleformat{\subsection}
{\normalfont\sffamily\large\fontfamily{phv}\selectfont}
{\thesubsection.}{.5em}{}[{\vspace{.2ex}\titleline{\color{mygray}\titlerule[1.5pt]}}]
\titleformat{\subsubsection}
{\normalfont\sffamily\normalsize\fontfamily{phv}\selectfont}
{\thesubsubsection.}{.5em}{}[{\vspace{.2ex}\titleline{\color{mygray}\titlerule[1pt]}}]
\begin{document}
\author{A}
\title{B}
\maketitle
%Table of Contents
\newpage
\renewcommand*\contentsname{Table of Contents}
\tableofcontents
\thispagestyle {empty}
\newpage
\setcounter{page}{1}
\section{Important Paths}
\subsection{trunk/Averylong/Bverylong/Cverylongverylong/Dverylongverylong/Everylong/Fverylong\_file\_Name.txt}
\subsection{trunk/Averylong/Bverylong/Cverylongverylong/Dverylongverylong/Everylong/Fverylong file Name.txt}
\subsection{t\hspace{0pt}r\hspace{0pt}u\hspace{0pt}n\hspace{0pt}k\hspace{0pt}/\hspace{0pt}A\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}B\hspace{0pt}v\hspace{0pt}e\hspace{0pt}rvy\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}C\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}D\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}E\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}v\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt}/\hspace{0pt}F\hspace{0pt}v\hspace{0pt}e\hspace{0pt}r\hspace{0pt}y\hspace{0pt}l\hspace{0pt}o\hspace{0pt}n\hspace{0pt}g\hspace{0pt} \hspace{0pt}f\hspace{0pt}i\hspace{0pt}l\hspace{0pt}e\hspace{0pt} \hspace{0pt}N\hspace{0pt}a\hspace{0pt}m\hspace{0pt}e\hspace{0pt}.\hspace{0pt}t\hspace{0pt}x\hspace{0pt}t\hspace{0pt}}
\end{document}
是否有一个简单的解决方案来归档此问题?
//更新:根据 David Carlisle 的建议,我采用了右对齐和斜线方法。这种方法对于章节标题很有效,但会破坏某些路径的目录。例如:
\subsection{trunk\slash trunk\slash Averylong\slash Bverylongverylong\slash Cverylongverylong\slash AdditionalCompilerSupportDefines.h}
this one breaks the toc
我创建了一个其他共享LaTeX文档来说明 toc 问题。
//更新:已解决:tocstyle 包提供了一个钩子,用于将 raggedright 应用于目录。请参阅https://tex.stackexchange.com/a/45164/115878&共享LaTeX文档
答案1
我只允许在处中断/
并将标题设置为右侧:
\documentclass[11pt,a4paper,fleqn]{scrartcl}
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[raggedright]{titlesec}
\usepackage[hidelinks]{hyperref}
\usepackage{xcolor}
% Color definitions
\colorlet{mygray}{gray!30}
% Customize headings
\titleformat{\section}
{\normalfont\sffamily\Large\fontfamily{phv}\selectfont}
{\thesection.}{.5em}{}[{\vspace{.2ex}\titleline{\color{mygray}\titlerule[2pt]}}]
\titleformat{\subsection}
{\normalfont\sffamily\large\fontfamily{phv}\selectfont\raggedright}
{\thesubsection.}{.5em}{}[{\vspace{.2ex}\titleline{\color{mygray}\titlerule[1.5pt]}}]
\titleformat{\subsubsection}
{\normalfont\sffamily\normalsize\fontfamily{phv}\selectfont}
{\thesubsubsection.}{.5em}{}[{\vspace{.2ex}\titleline{\color{mygray}\titlerule[1pt]}}]
\begin{document}
\author{A}
\title{B}
\maketitle
%Table of Contents
\newpage
\renewcommand*\contentsname{Table of Contents}
\tableofcontents
\thispagestyle {empty}
\newpage
\setcounter{page}{1}
\newcommand\?{\hspace{0pt}}
\section{Important Paths}
\subsection{trunk\slash Averylong\slash Bverylong\slash Cverylongverylong\slash Dverylongverylong\slash Everylong\slash Fverylong file Name.txt}
one with slash
\subsection{trunk\slash Averylong\slash Bverylong\slash Cverylongverylong\slash Dverylongverylong\slash Elong\slash Fverylong file Name.txt}
two with shorter title
\subsection{t\?r\?u\?n\?k\?/\?A\?v\?e\?r\?y\?l\?o\?n\?g\?/\?B\?v\?e\?rvy\?l\?o\?n\?g\?/\?C\?v\?e\?r\?y\?l\?o\?n\?g\?v\?e\?r\?y\?l\?o\?n\?g\?/\?D\?v\?e\?r\?y\?l\?o\?n\?g\?v\?e\?r\?y\?l\?o\?n\?g\?/\?E\?v\?e\?r\?y\?v\?l\?o\?n\?g\?/\?F\?v\?e\?r\?y\?l\?o\?n\?g\? \?f\?i\?l\?e\? \?N\?a\?m\?e\?.\?t\?x\?t\?}
one breaking mid-word
\subsection{t\?r\?u\?n\?k\?/\?A\?v\?e\?r\?y\?l\?o\?n\?g\?/\?B\?v\?e\?rvy\?l\?o\?n\?g\?/\?C\?v\?e\?r\?y\?l\?o\?n\?g\?v\?e\?r\?y\?l\?o\?n\?g\?/\?D\?v\?e\?r\?y\?l\?o\?n\?g\?v\?e\?r\?y\?l\?o\?n\?g\?/\?E\?l\?o\?n\?g\?/\?F\?v\?e\?r\?y\?l\?o\?n\?g\? \?f\?i\?l\?e\? \?N\?a\?m\?e\?.\?t\?x\?t\?}
two breaking mid-word
\end{document}