2

I have long paths as section headings and need proper line breaks. I don't need hyphens or any break rules.

\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}

The only way I can archive this is to add a hspace after each char. The output is exactly what I want it to be. But this doesn't seem to be a sane solution.

\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}}

The output is:

enter image description here

1.1 even reaches over the end of the pdf.

I have created a simple document on 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}

Is there a simple solution to archive this?

//UPDATE: As suggested by by David Carlisle I applied the raggedright and slash approach. It works fine for the section headings but breaks the toc for some paths. E.g.:

\subsection{trunk\slash trunk\slash Averylong\slash Bverylongverylong\slash Cverylongverylong\slash AdditionalCompilerSupportDefines.h}
this one breaks the toc

I'v created an other sharelatex document to illustrate the toc problem.

//UPDATE: Resolved: The package tocstyle provides a hook to apply raggedright to the toc. See https://tex.stackexchange.com/a/45164/115878 & sharelatex document

  • (1) welcome, (2) \path from the url package may help, need to test with your doc. \protect\path{trunk/Averylong/Bverylong/Cverylongverylong/Dverylongverylong/Everylong/Fverylong_file_Name.txt} wotks fine. Note there is then no need to escape _ – daleif Oct 7 '16 at 10:35
  • Thanks daleif but this breaks the section style as it uses typwriter font. – No3x Oct 7 '16 at 10:41
  • Then you need someone to help you configure \path, that is a different matter of which I have to time at the moment, sorry – daleif Oct 7 '16 at 10:47
  • Had a short break, this seems to work \DeclareUrlCommand\sfpath{\def\UrlFont{\fontfamily{phv}}}, note the \sffamily in your headings are probably being overwritten by \fontfamily. – daleif Oct 7 '16 at 11:08
  • use \slash instead of / and line breaking will be allowed – David Carlisle Oct 7 '16 at 11:13
1

I would allow breaking only at / and set the headings raggedright:

enter image description here

\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}
  • Thanks! This works fine for sections as required but breaks the toc. Try with this: \subsection{trunk\slash trunk\slash Averylong\slash Bverylongverylong\slash Cverylongverylong\slash AdditionalCompilerSupportDefines.h} this one breaks the toc – No3x Oct 7 '16 at 14:24
  • @No3x well yes you'd want to set the toc raggedright as well I don't know scr* classes that well, probably has some built in customisation for that. – David Carlisle Oct 7 '16 at 14:39
  • thanks for the hint. I'm very new to customize latex behaviour. I will try to set this to the toc as well somehow. – No3x Oct 7 '16 at 14:54
  • I was able to resolve this. See the updated question. – No3x Oct 10 '16 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.