fancyhead 左和右 [L] [R],与 tabula 垂直不对齐

fancyhead 左和右 [L] [R],与 tabula 垂直不对齐

我的头部左侧标题为“\leftmark \ \rightmark”,右侧标题为两行表格。但是,它们在垂直方向上并不对齐。如果我删除表格,只将右侧标题放在两条单独的行上,那么垂直对齐是正确的,但是我无法对齐学生姓名和学生编号。

作为表格,破坏了垂直对齐但具有良好的水平对齐:

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

表格破坏了垂直对齐,但具有良好的水平对齐

使用换行符,没有表格,垂直对齐良好,但水平对齐不佳:

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

换行符的垂直对齐效果很好,但水平对齐效果很差

下面包含一个最小工作示例,所有奇怪的额外代码都允许 \section{} 在章节页面上正确标记:

\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

欢迎来到 TeX、SE!

按照您对表中添加基线规范的定义:

\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}
    }

你将获得:

在此处输入图片描述

相关内容