This is answered in the TeX FAQ. On the left-hand pages the text used in the title is that of the first mark on the page, so your \subsectionmark
is coming too late. This can be solved by adding this command again in the title itself:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\tableofcontents
\section[some section with quite a lengthy title]{some section with quite
a lengthy title%
\sectionmark{short section}}
\sectionmark{short section}
\lipsum
\subsection[very very very long title of subsection]{very very very long
title of subsection%
\subsectionmark{short subsection}}
\subsectionmark{short subsection}
\lipsum
\end{document}
Because of the way the writing to the table of contents works you will also have to add the full title to the optional argument of the \(sub)section
command, as above. As this is rather clumsy, it is reasonable to introduced commands such as \markedsection
to achieve this:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newcommand{\markedsection}[2]{\section[#2]{#2%
\sectionmark{#1}}
\sectionmark{#1}}
\newcommand{\markedsubsection}[2]{\subsection[#2]{#2%
\subsectionmark{#1}}
\subsectionmark{#1}}
\begin{document}
\tableofcontents
\markedsection{short section}{Some section with quite a lengthy title}
\lipsum
\markedsubsection{short subsection}{Very very very long title of subsection}
\lipsum
\end{document}
For the standard cases, you can still use the ordinary commands.
If your are prepared to switch to the memoir
class, then you will have sectioning commands that help this proceedure as they have two optional arguments: one for the head and one for the table of contents.
If you don't set a proper head height, fancyhdr
reports the following:
Package Fancyhdr Warning: \headheight is too small (XX.Xpt):
Make it at least YY.YYYYpt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.
As such, the newly-set \headheight
will be the same throughout the document. To avoid this, I've created the following minimal document that sets a consistent head height, adding a vertical space (gap) on the first page to simulate a larger header:
\documentclass{article}
\usepackage{fancyhdr,datetime,geometry,lipsum,graphicx}
%%%%%%%%%%%%%%%%%%date in format Sunday, October 25, 2011
\usdate
\def\theday {\dayofweekname{\day}{\month}{\year}}
\def\mydate {\theday , \today}
%%%%%%%%%%return address%%%%%%%%%%
\def\myname {Frank Thorne}
\def\mydeptname {Department of Mathematics}
\def\myaffiliation {University of South Carolina}
\def\mystreet {1523 Greene Street}
\def\mycitystatezip {Columbia,~SC \quad 29208}
\def\myphone {\textit{Phone:} (803)404-4057 (home)}
\def\office {(803)777-4224}
\def\fax {\textit{Fax:}(803)777-3783}
\def\email {thorne@math.sc.edu}
\def\url {\texttt{http://www.math.sc.edu/~thornef}} % NOTE: use $\sim$ for tilde
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%margins%%%%%%%%%%%%%%%%%%
\geometry{
margin = 1in,
headheight = 13.5pt
}
\setlength{\parindent}{0pt} %controls how the indentation of new paragraphs behaves
\setlength{\parskip}{6pt} %controls the space between paragraphs
%%%%%%%%%%%%%%%%letterhead%%%%%%%%%%%%%%%%
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}%
\fancypagestyle{firstpage}{
\fancyhf{}% Clear header/footer
%%%usc logo
\fancyhead[L]{\raisebox{\dimexpr-\height+\baselineskip}[0pt][0pt]{\includegraphics[width=2.5in]{example-image}}}
%%%%%%%%%%return address on right%%%%%%%
\fancyhead[R]{\leavevmode\footnotesize\itshape%
\begin{tabular}[t]{l@{}}
\myname \\ \mydeptname \\
\myaffiliation \\ \mystreet \\
\mycitystatezip \\ \email \\[\normalbaselineskip]
\mydate
\end{tabular}}
}
\begin{document}
\thispagestyle{firstpage}
\vspace*{8\baselineskip}
\lipsum[1-10]
\bigskip
\hspace{.5\textwidth}%
\begin{tabular}{@{}l}
Sincerely, \\[2\normalbaselineskip]
Frank Thorne \\
\textit{Assistant Professor of Mathematics}
\end{tabular}
\end{document}
I've used geometry
to adjust the page layout - it's just easier/more convenient.
Best Answer
I guess your document is
oneside
? Then you can useIf your document is
twoside
there are two cases:TEMA 13 should be on the left hand side on even pages and on the right hand side on odd pages? Then you can use the same code as for the
oneside
option because thei
in\ohead
means "inner".TEMA 13 should be on the right hand side on both the even and the odd pages? Then you have to use
\lehead
and\lohead
(le
means left even,lo
left odd).Code for the second case: