I redefine my headers as in the following MWE:
\documentclass[12pt]{article}
\usepackage{xstring}
\usepackage{fancyhdr}
\fancypagestyle{monstyle}{%
\fancyhf{} % remove everything
\renewcommand{\headrule}{\rule[1.5ex]{\headwidth}{1pt}}
\lhead{%
\leftmark%
}
}
\begin{document}
\pagestyle{monstyle}
\section{le tres tres long titre qui prend trop de place sur la ligne}
\end{document}
The section title could be very long, like in my MWE, and i want to cut it at a fixed length (say 15 letters). My attempt is to use the command \StrLeft
from the package xstring
: I replace the line
\leftmark%
by
\StrLeft{\leftmark}{15}...%
But i get compilation errors which i do not understand:
Argument of \@iiparbox has an extra }.
EDIT
I try to use Mico's solution, but i encounter now a problem with the TOC :
\documentclass[12pt]{article}
\usepackage{xstring}
\usepackage{fancyhdr}
\usepackage{blindtext}
%% Redefine the short title
\let\origsection\section %
\renewcommand{\section}[1]{%
\def\ShortSecName{\StrLeft{#1}{10}...}
\origsection[\protect\ShortSecName]{#1}%
}
\begin{document}
\tableofcontents
\section{mon titre tres long tres tres long}
\blindtext\blindtext\blindtext
\section{mon titre tres long tres tres long}
\blindtext\blindtext\blindtext
\end{document}
I get the error :
! LaTeX Error: Something's wrong--perhaps a missing \item.
If i remove \tableofcontents
then it compiles.
Best Answer
An alternative approach would be using
titleps
instead offancyhdr
(caveat: I'm the author oftitleps
):\sectiontitle
is a macro containing just the title, not a mark with part of the header (formatted), and therefore it can be handled easily.