0

I am fighting with a very horrible master thesis template. Some smart _ss designed some features which couldn't be done in MS Word without manual correction so I'm trying to make it works in LaTeX to hack it.

I stuck on headers and footers. They should consist a horizontal line aligned with the chapter lines on and text. The header should have the capitalized chapter name. The footer should have a static text: "page" on the first line of text block and odd/even corner numbering on the second page. All with Verdana font.

See attached pictures.

I've tried to mess around with fandyhdr but my LaTeX skill is not good enough. Could somebody help me? Thank you.


Even footer with odd header


Odd footer with even header

Here is my template code:

\documentclass[a4paper,twoside]{report}% http://ctan.org/pkg/amsproc
\usepackage[top=3.00cm, bottom=3.00cm, inner=3cm, outer=3.5cm]{geometry}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[x11names,table]{xcolor}
\usepackage{fourier}
\usepackage{microtype}
\SetTracking[no ligatures={f}]{encoding=*}{80}
\usepackage[strict]{changepage}%
\usepackage{graphicx}
\usepackage[explicit]{titlesec}%
\usepackage[export]{adjustbox}
\usepackage{biblatex}
\usepackage{fancyhdr}
\usepackage{lipsum}


% BARVY
\definecolor{ukred}{RGB}{160,0,0}
\definecolor{ukgray}{RGB}{128,128,128}
\definecolor{ukredlight}{RGB}{160,0,0}
\definecolor{ukgraylight}{RGB}{192,192,192}

% TABULKY A OBRÁZKY
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\usepackage[font={color=ukgray},figurename=Obr.,tablename=Tab.,labelfont={color=ukgray,bf}]{caption}
\captionsetup{justification   = raggedright,singlelinecheck = false}

\counterwithout{table}{chapter}
\rowcolors{1}{ukgraylight}{white}

\renewcommand{\contentsname}{Obsah}

% NUMBERS AND LINES AT CAPTIONS
\titleformat{\chapter}[hang]
{\bfseries\fontsize{14pt}{14pt}\selectfont\color{ukred}\lsstyle}
{\checkoddpage\ifoddpage\llap{\makebox[\dimexpr\marginparsep+\marginparwidth\relax][l]{\rule[-1.25ex]{\marginparwidth}{0.5ex}\llap{}}}\thechapter\enspace\else\thechapter\enspace \fi}
{0pt}
{\MakeUppercase{#1}\checkoddpage\ifoddpage\else\hfill\rlap{\makebox[\dimexpr\textwidth + \marginparsep][l]{\hspace{\marginparsep}\rlap{\rule[-1.25ex]{\marginparwidth}{0.5ex}}\thechapter}}\fi}%\titlerule[1.5pt]
\titlespacing*{\chapter}{0pt}{2ex}{1ex}
%
\titleformat{\section}
{\bfseries\large}
{\checkoddpage\ifoddpage\llap{\makebox[\dimexpr\marginparsep+\marginparwidth\relax][l]{\rule[-1.25ex]{\marginparwidth}{0.5ex}\llap{}}}\thesection\enspace\else\thesection\enspace \fi}
{0pt}
{#1\checkoddpage\ifoddpage\else\hfill\rlap{\makebox[\dimexpr\textwidth + \marginparsep][l]{\hspace{\marginparsep}\rlap{\smash{\rule[-1.25ex]{\marginparwidth}{0.5ex}}}\thesection}}\fi}%\titlerule[1.5pt]
\titlespacing*{\section}{0pt}{1ex}{0.5ex}

\titleformat{\subsection}
{\bfseries}
{\checkoddpage\ifoddpage\llap{\makebox[\dimexpr\marginparsep+\marginparwidth\relax][l]{\rule[-1.25ex]{\marginparwidth}{0.5ex}\llap{}}}\thesubsection\enspace\else\thesubsection\enspace \fi}
{0pt}
{#1\checkoddpage\ifoddpage\else\hfill\rlap{\makebox[\dimexpr\textwidth + \marginparsep][l]{\hspace{\marginparsep}\rlap{\smash{\rule[-1.25ex]{\marginparwidth}{0.5ex}}}\thesubsection}}\fi} \titlespacing*{\subsection}{0pt}{1ex}{0.5ex}
%%%%%%%%%

% HEADER

% FOOTER
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[LE,RO]{\color{ukgraylight}\hrule height 2.84pt \vspace{0.1cm} \textsf{\small{strana}\\ \vspace{0.15cm} \textbf{\Large{\thepage}}}}

% CITACE
\addbibresource{citace.bib}

\begin{document}

\tableofcontents

\chapter{Nadpis 1. úrovně}

\lipsum[1]

\section{Nadpis 2. úrovně}
\lipsum[2]

\subsection{Nadpis 3. úrovně}

\lipsum[3]

\chapter{První kapitola dizertace}
\lipsum[1]\par
    Tady odcitujeme nějaký zdroj, ať víš, jak se vkládají. K tomu si budeš bohužel muset přečíst : \href{https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management}{tento článek:}, ale na druhou stranu, věř mi, že s přibývajícím zdroji se Ti to automatické generování stylu bude hodit. Citace pro \LaTeX Ti totiž umožní kde jaká slušná databáze, takže se Ti to ve výsledku všechno zjednoduší. Takže nějaké citace% \cite{einstein}. Nebo další \cite{dirac}.

\begin{figure}[ht!]
    \centering
    \includegraphics[width=110mm, cfbox = ukgray 1mm 0pt]{Auticko.png}
    \caption{Autíčko s tlustým popiskem bez názvu kapitoly, netlustým textem a pojebkaným rámečkem okolo...\label{overflow}}
\end{figure}
Tady bude zase nějaká tabulka...\par

\begin{table}[htb]
    \centering
    \caption{Nějaká tabulka}
%       \cfbox ukgray 1mm 0pt{
    \begin{tabular}{r|r|r|r}
        N & R & C &   T \\ \hline % odd -- lightblue (wrong)
        8 & 8 & 4 & 444 \\        % even 
        9 & 8 & 4 & 124 \\        % odd -- lightblue (wrong)
        10 & 8 & 4 & 672 \\        % even 
    \end{tabular}

\end{table}

\section{Nadpis 2. úrovně}
\lipsum[2]
\lipsum
\section{Nadpis 2. úrovně}
\lipsum
\lipsum

\chapter{Seznam použitých zkratek a symbolů}
\chapter{Seznam použitých zdrojů}
\printbibliography



\end{document} 
  • Why are you loading the caption more than once? And why is hyperref not the last package to be loaded? – user31729 Feb 25 '17 at 11:30
  • You can specify the header by using \fancyhead[LE]{Here is the text you want to see on Left head, Even pages}. There are also LO,RE,RO,CE,CO options – Michael Fraiman Feb 25 '17 at 11:33
  • To use Verdana you can do this: \usepackage{polyglossia} and \newfontfamily\HEADINGS{Verdana} in the preamble. To switch to Verdana simply type \HEADINGS where you want to. \titleformat{\chapter}[hang] {\bfseries\fontsize{14pt}{14pt}\HEADINGS\lsstyle} – Michael Fraiman Feb 25 '17 at 11:38
  • 1
    @MichaelFreimann If the OP uses Xe/LuaLaTeX. – TeXnician Feb 25 '17 at 11:42
  • To make line in headers and footers use \renewcommand\headrule{some code} and \renewcommand\footrule{some code}. The line itself is produced with \hrule. You can specify its width with \hrule height 2pt – Michael Fraiman Feb 25 '17 at 11:42
1

For the record, this is one of the worst styles I've seen. Not only does it not conform to standard typographical conventions. It does not even conform to its own. It is horribly inconsistent, lop-sided and distracting.

But if you have to use it, you have to use it. I would hate to try doing this in Word. It isn't much fun even in LaTeX.

  • The reason the side rule things are running to the paper's edge is because they use the width of the space allowed for marginal notes, but they are typeset on the opposite side of the text block, which does not allow room for such things. I've hard-coded the inner margin width, but you could pick this up programmatically if you needed to. The width of the rule is stored in \siderulewidth and set equal to 30mm less twice \marginparsep, in a vain attempt to keep at least some sense of symmetry.

  • fancyhdr provides macros for setting offset's for foot and head rules. We then have to compensate by adjusting for the weird placement of the header and footer content.

  • We use etoolbox to patch \footrule and \headrule for colour.

  • The titlesec configuration is altered to use \siderulewidth and to eliminate the need for \dimexpr, we load calc.

  • hyperref needs to be loaded last.

  • For the sake of the example, demo is used and the .bib altered as I don't have the files specified in the original.

The result is, I think, the desired awkwardness in all its lumbering glory.

lumbering glory

The code contains some additional explanation in the form of comments

\documentclass[a4paper,twoside, demo]{report}
\usepackage[top=3cm, bottom=3cm, inner=3cm, outer=3.5cm, headheight=18pt]{geometry}% 18pt is the minimum height required to accommodate the current header
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage[x11names,table]{xcolor}
\usepackage{graphicx}
\usepackage[strict]{changepage}
\usepackage{chngcntr}
\usepackage[export]{adjustbox}
\usepackage{fancyhdr}
\usepackage[explicit]{titlesec}
\usepackage[font={color=ukgray},figurename=Obr.,tablename=Tab.,labelfont={color=ukgray,bf}]{caption}
\usepackage{etoolbox,calc}
\usepackage{biblatex}
\usepackage{microtype}
\SetTracking[no ligatures={f}]{encoding=*}{80}
\usepackage{lipsum}

\usepackage{hyperref}% load last unless using cleveref or similar, which must be loaded right after

% BARVY
\definecolor{ukred}{RGB}{160,0,0}
\definecolor{ukgray}{RGB}{128,128,128}
\colorlet{ukredlight}{ukred!50}% not sure what this should be but presumably not identical to ukred - this makes mixes 50% ukred with 50% white
\definecolor{ukgraylight}{RGB}{192,192,192}

% TABULKY A OBRÁZKY
\counterwithout{figure}{chapter}
\captionsetup{justification   = raggedright,singlelinecheck = false}

\counterwithout{table}{chapter}
\rowcolors{1}{ukgraylight}{white}

\renewcommand{\contentsname}{Obsah}

% This is the width of the side rules.
\newlength\siderulewidth
% The inner margin is 30mm.
% This subtracts twice the value of \marginparsep, so the side rules will be \marginparsep from the text block and from the edge of the paper.
% \marginparwidth isn't suitable here because we are setting the rules in the inner margin and not the outer one.
\setlength\siderulewidth{30mm-2\marginparsep}

% NUMBERS AND LINES for sectional divisions (NOT captions)

% chapters
\titleformat{\chapter}[hang]
{\bfseries\fontsize{14pt}{14pt}\selectfont\color{ukred}\lsstyle}
{\checkoddpage\ifoddpage\llap{\makebox[\marginparsep+\siderulewidth\relax][l]{\rule[-1.25ex]{\siderulewidth}{0.5ex}\llap{}}}\thechapter\enspace\else\thechapter\enspace \fi}
{0pt}
{\MakeUppercase{#1}\checkoddpage\ifoddpage\else\hfill\rlap{\makebox[\textwidth + \marginparsep][l]{\hspace{\marginparsep}\rlap{\rule[-1.25ex]{\siderulewidth}{0.5ex}}\thechapter}}\fi}%\titlerule[1.5pt]
\titlespacing*{\chapter}{0pt}{2ex}{1ex}

% sections
\titleformat{\section}
{\bfseries\large}
{\checkoddpage\ifoddpage\llap{\makebox[\marginparsep+\siderulewidth\relax][l]{\rule[-1.25ex]{\siderulewidth}{0.5ex}\llap{}}}\thesection\enspace\else\thesection\enspace \fi}
{0pt}
{#1\checkoddpage\ifoddpage\else\hfill\rlap{\makebox[\textwidth + \marginparsep][l]{\hspace{\marginparsep}\rlap{\smash{\rule[-1.25ex]{\siderulewidth}{0.5ex}}}\thesection}}\fi}%\titlerule[1.5pt]
\titlespacing*{\section}{0pt}{1ex}{0.5ex}

% subsections
\titleformat{\subsection}
{\bfseries}
{\checkoddpage\ifoddpage\llap{\makebox[\marginparsep+\siderulewidth\relax][l]{\rule[-1.25ex]{\siderulewidth}{0.5ex}\llap{}}}\thesubsection\enspace\else\thesubsection\enspace \fi}
{0pt}
{#1\checkoddpage\ifoddpage\else\hfill\rlap{\makebox[\textwidth + \marginparsep][l]{\hspace{\marginparsep}\rlap{\smash{\rule[-1.25ex]{\siderulewidth}{0.5ex}}}\thesubsection}}\fi} \titlespacing*{\subsection}{0pt}{1ex}{0.5ex}


% FOOTER / HEADER
\fancyhf{}
% NOTE: style is not even consistent!!
\fancyfoot[RE]{% on even pages, the footer is in the inner margin
  \hspace*{\textwidth}%
  \begin{minipage}{\siderulewidth+\marginparsep}%
    \flushleft
    \color{ukgraylight}%
    \sffamily\small strana \\ \vspace{0.15cm} \textbf{\Large\thepage}%
  \end{minipage}%
}
\fancyfoot[LO]{% on odd pages, the footer begins at the end of the inner margin
  \hspace*{\dimexpr\siderulewidth+\marginparsep}%
  \begin{minipage}{\textwidth}%
    \flushleft
    \color{ukgraylight}%
    \sffamily\small strana \\ \vspace{0.15cm} \textbf{\Large\thepage}%
  \end{minipage}%
}
% header always goes on the left, regardless of page, but we need to account for the offset on odd pages
\fancyhf[loh]{\hspace*{\dimexpr\siderulewidth+\marginparsep}\color{ukgraylight}\Large\sffamily\MakeUppercase{\leftmark}}
\fancyhf[leh]{\color{ukgraylight}\Large\sffamily\MakeUppercase{\leftmark}}
% presumably these are meant to be the same
\renewcommand*\footrulewidth{2.84pt}
\renewcommand*\headrulewidth{2.84pt}
% set the offset for head and foot rules
\fancyheadoffset[ref,lof]{\marginparsep+\siderulewidth}
\makeatletter
% add colours for head and foot rules
\patchcmd{\footrule}{\hrule\@width}{\color{ukgraylight}\hrule\@width}{\typeout{footrule patched OK!}}{\typeout{Oh, no! Could not patch footrule.}}
\patchcmd{\headrule}{\hrule\@height}{\color{ukredlight}\hrule\@height}{\typeout{headrule patched OK!}}{\typeout{Oh, no! Could not patch headrule.}}
% abolish differences between plain and regular page styles
\let\ps@plain\ps@fancy
\makeatother
\pagestyle{fancy}
% we don't want numbers in the headers; we don't want section or subsections - just always the chapter name, so mark everything this way
\renewcommand{\chaptermark}[1]{% p.10 manual
  \markboth{#1}{}}

% CITACE
\addbibresource{biblatex-examples.bib}

\begin{document}

\tableofcontents

\chapter{Nadpis 1. úrovně}

\lipsum[1]

\section{Nadpis 2. úrovně}
\lipsum[2]

\subsection{Nadpis 3. úrovně}

\lipsum[3]

\chapter{První kapitola dizertace}
\lipsum[1]\par
    Tady odcitujeme nějaký zdroj, ať víš, jak se vkládají. K tomu si budeš bohužel muset přečíst : \href{https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management}{tento článek:}, ale na druhou stranu, věř mi, že s přibývajícím zdroji se Ti to automatické generování stylu bude hodit. Citace pro \LaTeX Ti totiž umožní kde jaká slušná databáze, takže se Ti to ve výsledku všechno zjednoduší. Takže nějaké citace% \cite{einstein}. Nebo další \cite{dirac}.

\begin{figure}[ht!]
    \centering
    \includegraphics[width=110mm, cfbox = ukgray 1mm 0pt]{Auticko.png}
    \caption{Autíčko s tlustým popiskem bez názvu kapitoly, netlustým textem a pojebkaným rámečkem okolo...\label{overflow}}
\end{figure}
Tady bude zase nějaká tabulka...\par

\begin{table}[htb]
    \centering
    \caption{Nějaká tabulka}
%       \cfbox ukgray 1mm 0pt{
    \begin{tabular}{r|r|r|r}
        N & R & C &   T \\ \hline % odd -- lightblue (wrong)
        8 & 8 & 4 & 444 \\        % even
        9 & 8 & 4 & 124 \\        % odd -- lightblue (wrong)
        10 & 8 & 4 & 672 \\        % even
    \end{tabular}

\end{table}

\section{Nadpis 2. úrovně}
\lipsum[2]
\lipsum
\section{Nadpis 2. úrovně}
\lipsum
\lipsum

\chapter{Seznam použitých zkratek a symbolů}
\chapter{Seznam použitých zdrojů}
\printbibliography

\end{document}
  • I would say it better. I totally agree. I could write you some funny stories about the institute where this template is used but this isn't a right place to do it. And you wouldn't believe me anyway. For example this template design came from the industrial design department of the institute. But anyway... Big thanks for your help! – KUTlime Feb 26 '17 at 13:00
  • I added the \usepackage{boxhandler} for the boxed caption aligned with the picture width but the custom figurename label has a horizontal offset from other caption text when the caption text is longer than one line. I can't find why. i.stack.imgur.com/53Mby.png % Here is an example how to push a boxed picture into the document. \begin{center} \bxfigure[h]{\label{fig:somepic}Popisek obrázku, který může být klidně delší než jeden řádek, ale lze ho zalomit i ručně.}{ \includegraphics[width=110mm, cfbox = ukgray 1mm 0pt]{auticko.png} } \end{center} – KUTlime Mar 1 '17 at 0:10
  • Captions are quite different from headers and footers. Unless I'm missing something, this is a completely different question. If so, ask a new question with a proper minimal example. It doesn't belong (and cannot be adequately addressed) in comments. – cfr Mar 1 '17 at 0:20
  • I've solved the problem with a different float package. Thx for reply. – KUTlime Mar 1 '17 at 0:31
  • Nightmare continues... Is there any way how to avoid these type of problems? i.stack.imgur.com/ElA1r.png & i.stack.imgur.com/CzwHO.png Unfortunately, I can't change the chapter titles. – KUTlime Mar 1 '17 at 22:14

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.