2

I am trying to prevent justification in my header.

I have tried \raggedright so far suggested here How to prevent automatic justification of references? but no luck with this

\makeatletter
\renewcommand{\@oddhead}
{\raggedright\fontsize{10}{12}\selectfont OpenGl ES 3.0 and WebGl 1.0.2 on Android platform}
\makeatother
Patryk
  • 961

2 Answers2

2

To center the content use \hfill <text here>\hfill, as shown below.

Note that \oddhead is not used on even pages if you use the twoside option with the class. So if you want different headers redefine both commands: \oddhead and \evenhead.

\documentclass[twoside]{report}
\usepackage{lipsum} %% dummy text

\makeatletter
\renewcommand{\@oddhead}
{\fontsize{10}{12}\selectfont\hfill Header for odd pages\hfill}

\renewcommand{\@evenhead}
{\fontsize{10}{12}\selectfont\hfill Header for even pages\hfill}
\makeatother

\begin{document}
\lipsum
\end{document}

enter image description here

Sigur
  • 37,330
1

I realise this question is already answered but I thought it might be worth mentioning an alternative solution using the fancyheadings package. While possibly overkill for this particular case, it provides flexible configuration of both headers and footers, and so has the potential to provide solutions to a range of variations on the theme of this question.

Headers and footers are here thought of as having 3 parts - left, centre and right. Odd and even headers/footers can be configured differently for two-sided documents, although it is also possible to simplify the configuration commands when things should be repeated. In addition, commands are provided to insert rules beneath headers or above footers. By default, a rule is provided beneath the header but no rule is drawn for footers. All of this is highly configurable, though.

For full details, you'd want to read the documentation. However, I've tried to indicate the basic options available by commenting the code which would answer the particular question asked here.

\documentclass[twoside]{report}
\usepackage{lipsum} %% dummy text
\usepackage{fancyhdr}

\pagestyle{fancy}
% unset defaults - no optional argument so this sets everything to empty
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
% set what you need
% reset the width of the header rule to the package default
% \renewcommand{\headrulewidth}{0.4pt}
% add a corresponding rule above footers
% \renewcommand{\footrulewidth}{0.4pt}
% \fancyhf[loh]{\fontsize{10}{12}\selectfont Left, odd header part}
\fancyhf[coh]{\fontsize{10}{12}\selectfont Centre, odd header part}
% \fancyhf[roh]{\fontsize{10}{12}\selectfont Right, odd header part}
% \fancyhf[leh]{\fontsize{10}{12}\selectfont Left, even header part}
\fancyhf[ceh]{\fontsize{10}{12}\selectfont Centre, even header part}
% \fancyhf[reh]{\fontsize{10}{12}\selectfont Right, even header part}
% \fancyhf[lof]{\fontsize{10}{12}\selectfont Left, odd footer part}
% \fancyhf[cof]{\fontsize{10}{12}\selectfont Centre, odd footer part}
% \fancyhf[rof]{\fontsize{10}{12}\selectfont Right, odd footer part}
% \fancyhf[lef]{\fontsize{10}{12}\selectfont Left, even footer part}
% \fancyhf[cef]{\fontsize{10}{12}\selectfont Centre, even footer part}
% \fancyhf[ref]{\fontsize{10}{12}\selectfont Right, even footer part}
% for single-sided or in case the same centre header is wanted for odd and even pages
% \fancyhf[ch]{\fontsize{10}{12}\selectfont Common central header part}

\begin{document}
\lipsum
\end{document}

This produces

enter image description here

cfr
  • 198,882
  • fancyheadings is obsolete and fancyhdr should be used. Actually fancyheadings just displays a warning and loads fancyhdr. – egreg Dec 28 '13 at 20:46
  • Thanks. I always get it the wrong way around. Should have checked the docs (or my own comments in my custom package). I think what tends to happen is I guess fancyhf and when that gives me an error, I think it must be a longer version. – cfr Dec 28 '13 at 21:09