
У меня есть следующий код для нижнего колонтитула:
\usepackage{fancyhdr}
\lhead{}
\rhead{}
\chead{My very important and long title that is not being centered as I would like to \newline Very Myself}
\cfoot{\thepage}
\setlength{\headheight}{14pt}
но он не центрирован:
Как мне его отцентрировать? Я использую\documentclass[11pt,a4paper]{article}
решение1
Используйте \\
и не \newline
. Поведение легко воспроизводимо:
\fbox{\parbox{5cm}{\centering A centered\\ text}}
\medskip
\fbox{\parbox{5cm}{\centering A centered\newline text}}
дает
Вот код для вас
\documentclass{article}
\usepackage{geometry,fancyhdr}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\chead{%
My very important and long title that is not being centered as I would like to \\ Very Myself
}
\cfoot{\thepage}
\setlength{\headheight}{24pt}
\begin{document}
\section{A section}
\end{document}
Команда \\
меняет свое значение в \centering
контексте, который действует в \chead
, а \newline
не в .
решение2
Установите заголовок внутри tabular
, так как перенос строк (с использованием \newline
) не работает должным образом внутри полей заголовка:
\documentclass{article}
\usepackage{geometry,fancyhdr}
\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\chead{\begin{tabular}{c}
My very important and long title that is not being centered as I would like to \\ Very Myself
\end{tabular}}
\cfoot{\thepage}
\setlength{\headheight}{24pt}
\begin{document}
\section{A section}
\end{document}