0

I am using this template: http://www.fluortools.com/misc/LaTeXtemplate

and I have this defined in formatAndDefs.tex file

\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.pathmorphing,arrows,matrix,positioning,patterns}

\titlespacing*{\chapter}{0cm}{-1.cm}{-40pt}%pbk
\titleformat{\chapter}[display]{\Huge\filleft\scshape}{ \normalfont\bf\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thechapter}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}]
%
\titlespacing*{\part}{-10pt}{120pt}{-80pt}%pbk
\titleformat{\part}[frame]{\Huge\filcenter\scshape}{ \normalfont\bf\fontsize{85pt}{0pt}\selectfont \raisebox{1.7cm}{ Part\fontfamily{put}\fontseries{b}\fontsize{105pt}{0pt}\selectfont \hspace{.2em}\thepart} }{30pt}{}[\filright]

 \newcommand\boxedSection[3]{{%
%
     \begin{tikzpicture}[inner sep=#3,line width=1.0pt]
         \node[] at (0,0) (counter) {\textbf{#2}};
            %  \draw (counter.south west)  ++(.0pt,.1pt)-- ++($(\linewidth,0) - (0.5pt,0)$);
\node [right of=counter,anchor=west]{\textbf{#1}};
     \end{tikzpicture}
 }}
 \newcommand\boxedSectionB[3]{{%
%
     \begin{tikzpicture}[inner sep=#3,line width=1pt]
         \node[anchor=east,rectangle,draw,fill=black] at (0,0) (counter) {\color{white}\textbf{#2}};
             \draw (counter.south west) ++(.0pt,.5pt)-- ++($(\linewidth,0) - (2.5pt,0)$);
\node [right of=counter,anchor=west]{#1};
     \end{tikzpicture}
 }}
\newcommand\boxedsection[1]{\boxedSectionB{#1}{\thesection}{2mm}}
\newcommand\boxedsubsection[1]{\boxedSection{#1}{\thesubsection}{1.7mm}}
\newcommand\boxedsubsubsection[1]{\boxedSection{#1}{\thesubsubsection}{1.6mm}}
 \titleformat{\section}[hang]%
     {\usekomafont{section}}%
     {}%
     {.0em}%
     {\filright\boxedsection}%

 \titleformat{\subsection}[hang]%
     {\usekomafont{subsection}}%
     {}%
     {.0em}%
     {\filright\boxedsubsection}%
 \titleformat{\subsubsection}[hang]%
     {\usekomafont{subsubsection}}%
     {}%
     {.0em}%
     {\filright\boxedsubsubsection}%

Everything works fine if the title of my section is short. But when I have a long title, I get this (attached image):

\section{This is a very very very very long title for this section}

enter image description here

How can I allow multiple lines for the section's title?

5
  • 2
    I would strongly recommend against letting the running title in the header area occupy more than one row. Instead, do use the optional argument of \section to create a shortened section title for the header area. E.g., \section[Section with long title]{This is a very very very very long title for this section}. There is neither a semantic need nor a typographic justfication for repeating the complete long section title in the header area.
    – Mico
    Commented Apr 5, 2022 at 21:35
  • Thansk @Mico. Could you please help me to edit the formatAndDefs.tex to define the section with the optional argument [Section with long title]?
    – Laura
    Commented Apr 5, 2022 at 21:48
  • Does the code I provided in my initial comment not work?
    – Mico
    Commented Apr 5, 2022 at 21:56
  • 1
    @Mico I downloaded the template and tested. Your method does work for setting a shorter title in the header. (Moreover, multiline headers are already allowed in the template!) However, what we're looking at in Laura's screenshot is the actual section heading at its start (not the header) where using the shorter title is not appropriate.
    – frabjous
    Commented Apr 5, 2022 at 23:12
  • 1
    @frabjous - Thanks for clearing up this misunderstanding of mine. I was indeed under the (erroneous!) impression that the screenshot showed material in the header.
    – Mico
    Commented Apr 5, 2022 at 23:28

1 Answer 1

2

The problem is that this particular template typesets section and subsection headings directly inside TikZ nodes, which do not support linewrapping as a general rule.

This way of handling section headings is very unusual and not really a great idea. Whoever developed the template should rethink the design.

As a temporary kludge, you might change the definition of \boxedSectionB to insert a \parbox for the text rather than the text as is. My suggested code is below. However, I'm using some trickery with \smash and \vphantom to prevent the node from centering away from the baseline, and I just arrived at the 10cm width for the parbox by trial and error, since I'm not aware of a good way to calculate the exact width remaining at the place where the node starts.

You may need to fiddle with the 10cm, especially if you're going to have chapter numbers with more than single digits.

Also, you're still going to be out of luck if the section heading gets longer than two lines, since the TikZ picture just isn't big enough for that.

 \newcommand\boxedSectionB[3]{{%
%
     \begin{tikzpicture}[inner sep=#3,line width=1pt]
         \node[anchor=east,rectangle,draw,fill=black] at (0,0) (counter) {\color{white}\textbf{#2}};
             \draw (counter.south west) ++(.0pt,.5pt)-- ++($(\linewidth,0) - (2.5pt,0)$);
         \node [right of=counter,anchor=west]{\vphantom{X}\smash{\parbox[b]{10cm}{#1}}};
     \end{tikzpicture}
 }}

tikz heading output

If you have long sub(sub)section titles, you'll probably want to edit the definition of \boxedSection (no B) right above it in a similar way, but I'll let you work out the details.

Really, it's just poor design on the part of template maker, and in your shoes, I would either use a different template (if you're allowed) or ask them to come up with a better solution if you're in a position to do so.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .