中央ヘッダーが中央に配置されていません

中央ヘッダーが中央に配置されていません

フッターには次のコードがあります:

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

関連情報