2

My head has "\leftmark \ \rightmark" as the left header, and a 2 row tabular as the right header. However these do not vertically align with each other. If i remove the tabular and just put the right header on two separate lines, then the vertical alginment is correct, but then i cannot align the student name and student number.

As a tabular, breaks vertical alignment but has good horizontal alignment:

\newcommand{\writer}{
    \begin{tabular}{l l}
        Student Name:& John Smith\\
        Student Number:& 42069420
    \end{tabular}
    }

Tabular breaks vertical alignment but has good horizontal alignment

Using newline, without a tabular has good vertical alignment but bad horizontal alignment:

\newcommand{\writer}{
        Student Name: John Smith\\
        Student Number: 42069420
    }

Newline has good vertical alignment but bad horizontal alignment

Included below is a minimum working example, all the weird extra code allows \section{} to be right marked correctly on chapter pages:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{chngcntr}                           %defines \counterwithout    %does the sectionmark correctly
\usepackage{xpatch}                             %no idea??                  %does the sectionmark correctly
\usepackage{scrextend}                          %defines \Ifstr             %does the sectionmark correctly

%%%%%%%%%%Author deets (used in header)
\newcommand{\writer}{
    \begin{tabular}{l l}
        Student Name: John Smith\\
        Student Number: 42069420
    \end{tabular}
    }

%%%%%%%%%%Default page style
\pagestyle{fancy}

%%%%%%%%%%Section/chapter mark formatting
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}


%%%%%%%%%%Headers and Footers
%%%%%%%%%%DONT TOUCH! Fixes section marks on chapter pages%%%%%%%%%%%
\makeatletter
\providecommand*{\rightbotmark}{\expandafter\@rightmark\botmark\@empty\@empty}
\makeatother

\newmarks\mysection
\xapptocmd\sectionmark{\marks\mysection{\thesection. \ #1}}{}{}

%%%Default header settings
\fancyhf{}
\setlength{\headheight}{32pt}
\fancyhead[L]{\leftmark \\
        \rightmark
        }
\fancyhead[R]{\writer}

%%%Plain Headers and Footer (Chapter pages)
\fancypagestyle{plain}{
    \fancyhf{}
    \setlength{\headheight}{32pt}
    \fancyhead[L]{\leftmark\\
                    \Ifstr{\rightmark}{}{\Ifstr{\rightbotmark}{}{}{\firstmarks\mysection}}%
                        {\Ifstr{\rightmark}{\leftmark}{}{\rightmark}}
                }
    \fancyhead[R]{\writer}
}


\begin{document}
\chapter{Introduction}
text
\section{Section 1}
text2
\end{document}

1 Answer 1

1

Welcome to TeX,SE!

To your definition of the add baseline specification to table:

\newcommand{\writer}{
    \begin{tabular}[b]{l l} % <--- table baseline is now at bottom line in the table
        Student Name:   &   John Smith\\
        Student Number: &   42069420
    \end{tabular}
    }

and you will get:

enter image description here

2
  • So simple! I was trying to use 'b', but badly getting the syntax wrong. Thank you for showing me correctly.! Is there a way to mark the thread as solved/answered or something? I am new
    – bitmods
    Mar 28, 2021 at 6:52
  • @bitmods, with accepting of answer the thread is considered as "solved". Thank you very much!
    – Zarko
    Mar 28, 2021 at 6:56

You must log in to answer this question.

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