The issue is simple: fancyhdr
has done exactly what you asked:
\fancyfoot[C]{%
\hspace{20em}book title
}
20em is not a fixed width because it is font-dependent, but, in most cases, it is a significant chunk of the width of the text block. To see what is happening, just add x
before the space,
\fancyfoot[C]{%
x\hspace{20em}book title
}
Exactly the same happens on odd pages, but the result happens not to be overlapping text.
So if you want to use long titles rather than shortened versions in the footers, you do need something other than the tripartite division provided by fancyhdr
. To avoid that, you could tweak your hack to put the \hspace
in the right place.
\fancyfoot[CO]{%
\hspace{20em}book title%
}
\fancyfoot[CE]{%
book title\hspace{20em}%
}
Alternatively, you could use a tabularx
setup with or without fancyhdr
's assistance. It's hard to think what alignment you have in mind here, but perhaps something like the following, which assumes the title is never so long as to run to a second line,
\fancyfoot[CO]{%
\begin{tabularx}{\textwidth}{@{}l|>{\centering}X|r@{}}
here is the title of the chapter, sometime long & book title & \thepage \tabularnewline
\end{tabularx}%
}
\fancyfoot[CE]{%
\begin{tabularx}{\textwidth}{@{}l|>{\centering}X|r@{}}
\thepage & book title & here is the title of the chapter, sometime long \tabularnewline
\end{tabularx}%
}
As David explained, any tabularx
must include at least one X
column.
If the title might run to a second line, you need to allow for that and that means the chapter needs an/the X
, which makes alignment trickier. In that case you really don't want vertical rules (which I wouldn't use anyway, but nobody would use them here), so maybe something like
\fancyfoot[CO]{%
\begin{tabularx}{\textwidth}{@{}Xcr@{}}
here is the title of the chapter, sometimes ridiculously, absurdly, incredibly, magnificently long & book title & \hspace*{10mm}\thepage \tabularnewline
\end{tabularx}%
}
\fancyfoot[CE]{%
\begin{tabularx}{\textwidth}{@{}lc>{\raggedleft}X@{}}
\thepage\hspace*{10mm} & book title & here is the title of the chapter, sometimes ridiculously, absurdly, incredibly, magnificently long \tabularnewline
\end{tabularx}%
}
Or you could use tabular*
rather than tabularx
, as David also suggested.
I would post images, but I can't crop multipage output and conversion takes a significant amount of time and insists on converting all pages, so you'll have to compile and/or run them for yourself as Okular still haven't fixed the bug on X.
\begin{tabularx}{\textwidth}{@{}c|c|c@{}}
never usetabularx
with noX
column, it has no way to use the stated width. usetabular*
here (if yo want a table at all, which seems unnecessary)fancyhdr
already gives you the option to specify left centered and left parts, why use a tabular?tabularx
but at the time of writing this post i forgot to mention it. With this post i wanted to solve both the problem oftabularx
width in the footer and the slight displacement towards right or left of the middle field in the footer. Today for the document I'm currently working on, the latter solution is fine. But in the future If I ever have very long strings I might have to use thetabularx
option