1

Ok here is my minimized .tex file:

\documentclass[12pt,twoside]{article}

\usepackage{lipsum}

\usepackage{fancyhdr}                                               % pagina

\fancyfoot{}                                                        % styl paginy
\fancyhead[RO,LE]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\fancypagestyle{plain}{
   \fancyhf{}                                                       % empty header and footer
   \renewcommand{\headrulewidth}{0pt}                               % ho header line
   \renewcommand{\footrulewidth}{0pt}                               % not footer line
}

\usepackage[a4paper,                                    % wymiary strony
        left=3.5cm,
        right=2cm,
        top=2cm,
        bottom=2cm,
        includefoot=false,
        includehead=false]{geometry}
\usepackage{emptypage}                                  % brak numeracji na pustych stronach

\title{xxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxx}
\author{xxxxxxxxxxxxxxxxxxxx}                               % autor
%Preambuła_koniec
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dokument_start
\begin{document}

\maketitle                                              % strona tytulowa

\cleardoublepage

\vspace*{\fill}
\begin{flushright}
tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst
\end{flushright}
\vspace*{\fill}

\cleardoublepage

\tableofcontents                                        % spis tresci

\cleardoublepage

\newgeometry{left=3.5cm,                                % redefiniowana geometria
        right=2cm,
        top=2cm,
        bottom=2cm,
        includefoot=false,
        includehead}

\pagestyle{fancy}

\section{section}
\thispagestyle{plain}
\subsection{subsection}

\lipsum
\lipsum
\lipsum
\lipsum
\lipsum

\cleardoublepage

\section{section2}
\thispagestyle{plain}
\subsection{subsection2}

\lipsum
\lipsum
\lipsum
\lipsum
\lipsum

\end{document}

this:

\fancyfoot{}                                                        % styl paginy
\fancyhead[RO,LE]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\fancypagestyle{plain}{
   \fancyhf{}                                                       % empty header and footer
   \renewcommand{\headrulewidth}{0pt}                               % ho header line
   \renewcommand{\footrulewidth}{0pt}                               % not footer line
}

should compile header with section title on right and page number on left in even pages, and subsection on left and page number on right in odd pages. BUT it only shows page number in pdf file after compilation:

(even) 8_____________________

(odd) _____________________9

shoudl be this:

(even) 8_________sectiontitle

(odd) subsectiontitle______9

Thanks for help!

Here is my full preamble and sample .tex with @cfr correction, but now instead of section and subsection titles there is "table of content" in my header

\documentclass[12pt,twoside]{article}   % rozmiar czcionki, druk dwustronny, klasa mwart

\usepackage{palatino}                   % czcionka Palatino
\usepackage[T1]{fontenc}                % wymagane do dzialania czcionki Palatino
\linespread{1.05}                       % interlinia, 1.05 ze wzgledu na czcionke Palatino


\usepackage[utf8]{inputenc}             % kodowanie dokumentu
\usepackage[english,polish]{babel}      % kroj czcionki w jezyku polskim i angielskim
\usepackage[MeX]{polski}                % slownik lamania wyrazow w jezyku polskim

\usepackage[a4paper,                    % wymiary strony
        left=3.5cm,
        right=2cm,
        top=2cm,
        bottom=2cm,
        headheight=15pt,
        includefoot=false,
        includehead=false]{geometry}

\usepackage{csquotes}                   % cudzyslowy
\usepackage{graphicx}                   % pakiet graficzny, wymagany do wstawiania rysunkow
\usepackage{float}                      % rysunki w zadanym miejscu
\usepackage{enumitem}                   % spis tresci i listy
\usepackage{indentfirst}                % aktywne pierwsze wciecie w akapicie
\usepackage{etoolbox}                   % pakiet umozliwiajacy edycje domyslnych komend
\usepackage{amsmath}                    % pakiet matematyczny
\usepackage{bm}                         % dla pogrubionych i pochylonych czcionek w srodowisku matematycznym
\usepackage{ragged2e}
\usepackage[font=footnotesize,          % otoczenie podpisow tabel i rysunkow
        justification=RaggedRight,
        singlelinecheck=false,
        format=hang,
        labelfont=bf,
        labelsep=period,
        compatibility=false]{caption}
\usepackage{titling}                    % tytulowanie
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%


\usepackage{tocloft}                                                % spis tresci wraz z komenda dla kropek w rozdzialach

\renewcommand\cftsecleader{\cftdotfill{\cftdotsep}}


\usepackage[compact]{titlesec}                                      % zmiana czcionki i odstepow w tytulach rozdzialow

\titleformat{\section}
  {\normalfont\fontsize{16pt}{16pt}\bfseries}
  {\makebox[\mylen][l]{\thesection.}}
  {0pt}
  {}

\titleformat{\subsection}
  {\normalfont\fontsize{14pt}{14pt}\bfseries}
  {\makebox[\mylen][l]{\thesubsection.}}
  {0pt}
  {}

\titleformat{\subsubsection}
  {\normalfont\fontsize{12pt}{12pt}\bfseries}
  {\makebox[\mylen][l]{\thesubsubsection.}}
  {0pt}
  {}

\titlespacing*{\section}{0pt}{*0}{14pt}                             % zmiana odstepow po tytulach rozdzialow
\titlespacing*{\subsection}{0pt}{14pt}{12pt}
\titlespacing*{\subsubsection}{0pt}{12pt}{0pt}


\DeclareQuoteAlias{croatian}{polish}                                % deklaracja cudzyslowow


\setlist[enumerate,1]{label=\arabic*),leftmargin=1.25cm}            % odsuniecie wypunktowania
\setlist[itemize,1]{label=-,labelsep=0.4cm,leftmargin=1.25cm}
\setlist[itemize,2]{label=-,labelsep=0.4cm,leftmargin=0.6cm}


\setlength\parindent{1.25cm}                                        % wciecie 1.25cm
\newlength\mylen
\setlength\mylen{\parindent}


\addto\captionspolish{\renewcommand{\figurename}{Rys.}}             % zmiana domyslnego podpisu dla rysunku


\renewcommand{\thetable}{\arabic{section}.\arabic{table}}           % zmiana domyslnej numeracji dla rysunkow itp.
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}


\usepackage{fancyhdr}                                               % pagina

\fancyfoot{}                                                        % styl paginy
\fancyhead[RO,LE]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}

\fancypagestyle{plain}{
   \fancyhf{}                                                       % empty header and footer
   \renewcommand{\headrulewidth}{0pt}                               % ho header line
   \renewcommand{\footrulewidth}{0pt}                               % not footer line
}


%%%%%%%%%%%%%%%%%%%%%%%%                                            % strona tytulowa (en.wikibooks.org/wiki/LaTeX/Title_Creation)
\renewcommand*{\maketitle}{
\begin{titlepage}
    \centering
    \vspace{2cm}
    {\Large \textbf{xxxxxxxxxxx}\par}
    \vspace{2cm}
    {\LARGE \textbf{xxxxxxxxxxxx}\par}
    \vspace{2cm}
    {\Large \textbf{\theauthor}\par}
    {\Large xxxxxxxxxxxxxxxx\par}
    \vspace{1cm}
    \rule{0.8\textwidth}{1.5pt}

    {\LARGE \thetitle\par}

    \rule{0.8\textwidth}{1.5pt}

    \vfill

    {\Large xxxxxxxxxxx\\xxxxxxxxxxxxxxxx\par}
    \vspace{1cm}
    {\Large xxxxxxxxxxxxxxx}
\end{titlepage}
}
%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%                                            % komendy do bibliografii
                                    % brak kropek na końcu refa
%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{lipsum}

\hyphenation{Stren-gth}                                 % dzielenie wyrazow
\newcommand{\varA}[1]{{\operatorname{\mathit{#1}}}}     % zmienna matematyczna
\usepackage{emptypage}                                  % brak numeracji na pustych stronach

\title{xxxxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxxxxxx}
\author{xxxxxxxxxxxxxxxx}                               % autor
\begin{document}
\begingroup
\pagestyle{plain}
\maketitle                                              % strona tytulowa
\cleardoublepage

\vspace*{\fill}
\begin{flushright}
tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst
\end{flushright}
\vspace*{\fill}

\cleardoublepage

\tableofcontents                                        % spis tresci

\cleardoublepage

\endgroup

\newgeometry{left=3.5cm,                                % redefiniowana geometria
        right=2cm,
        top=2cm,
        bottom=2cm,
        headheight=15pt,
        includefoot=false,
        includehead}

\pagestyle{fancy}

\section{section1}
\thispagestyle{plain}
\label{sec:wstep}
\subsection{subsection1}
\lipsum
\lipsum
\lipsum
\lipsum

\subsection{subsection2}
\lipsum
\lipsum
\lipsum
\lipsum

\subsection{subsection3}
\lipsum
\lipsum
\lipsum

\cleardoublepage

\section{section3}
\thispagestyle{plain}
\label{sec:geometria}
\subsection{subsection4}
\lipsum
\lipsum
\lipsum
\lipsum

\subsubsection{subsection5}
\lipsum
\lipsum
\lipsum
\lipsum

\clearpage

\end{document}
3
  • 2
    Could you please minimize your code to a single file which only uses the packages and code that is necessary to reproduce your problem? I tried with a small document with that only sets the pagestyles, and it seems to work fine.
    – siracusa
    Jul 26, 2017 at 5:47
  • Will do it but within couple of hours, I don't have accesd to my laptop right now, thanks ;)
    – MajkelTMB
    Jul 26, 2017 at 6:05
  • I changed my code @siracusa the output header is a little bit different but the key of problem is the same.
    – MajkelTMB
    Jul 26, 2017 at 20:46

1 Answer 1

1

I would strongly encourage you to utilise a more appropriate class. Using article is thumbing your nose at existing solutions for absolutely no reason at all.

However, if you are sufficiently bloody-minded to insist on trying to screw nails using a compass, then the following code will solve your immediate difficulties, though not your later headaches, dodgy home decor and sore nose.

  • Put what would be the \frontmatter with any self-respecting class for documents of this kind into a group.

  • Load geometry before fancyhdr.

  • Remember to comment line endings where needed.

  • Do not use \pagestyle{plain} in the main body of the document. Use it only with the front matter group or similar.

  • Read the warnings: your header needs a height of at least 15pt. Tell `geometry that.

  • Dice boldly with a thousand typographic deaths.

\documentclass[12pt,twoside,a4paper]{article}
\usepackage{lipsum}

\usepackage[%
left=3.5cm,
right=2cm,
top=2cm,
bottom=2cm,
headheight=15pt,% minimum required
includefoot=false,
includehead=false,
]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[RE]{\nouppercase{\leftmark}}
\fancyhead[LO]{\nouppercase{\rightmark}}
\fancypagestyle{plain}{%
   \fancyhf{}%
   \renewcommand{\headrulewidth}{0pt}%
   \renewcommand{\footrulewidth}{0pt}%
}
\usepackage{emptypage}

\title{xxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxx}
\author{xxxxxxxxxxxxxxxxxxxx}
\begin{document}
\begingroup
\pagestyle{plain}
\maketitle
\cleardoublepage

\vspace*{\fill}
\begin{flushright}
tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst tekst tekst tekst tekst tekst tekst tekst tekst\\ tekst tekst
\end{flushright}
\vspace*{\fill}

\cleardoublepage

\tableofcontents

\cleardoublepage

\endgroup

\newgeometry{%
  left=3.5cm,
  right=2cm,
  top=2cm,
  bottom=2cm,
  includefoot=false,
  headheight=15pt,% minimum required
  includehead}

\pagestyle{fancy}

\section{section}
\thispagestyle{plain}
\subsection{subsection}

\lipsum
\lipsum
\lipsum
\lipsum
\lipsum

\cleardoublepage

\section{section2}
\thispagestyle{plain}
\subsection{subsection2}

\lipsum
\lipsum
\lipsum
\lipsum
\lipsum

\end{document}
4
  • I made new .tex file with your correction and added it to my first post with my full preamble, still there is something wrong asa I pointed out, could you check this, thanks
    – MajkelTMB
    Jul 27, 2017 at 8:18
  • @MajkelTMB Make sure my code gives you what you expect. Then add things one-by-one or a few at a time until you find the thing responsible for the new problem. It is unlikely that, say, graphicx or enumitem is responsible, so try adding something like tocloft first.
    – cfr
    Jul 27, 2017 at 12:38
  • After copying all the preamble to your modified structure everything is working right now, one change I've made was deleting renewcommand maketitle, and paste this section just after begin{document}, seems that none package was causing the problem, thank you so much for your time :)! Also what class do you recommend for thesis? I renewed fancy commands to have first pages of sections without header and footer. @cfr
    – MajkelTMB
    Jul 27, 2017 at 14:04
  • @MajkelTMB If you have to keep to very precise requirements (e.g. in the US), I'd recommend book or amsbook (for maths). Otherwise, KOMA book or Memoir. report is also an option, but not such a good choice if you need front matter and double-sided printing. If you want to keep fancyhdr, geometry, titlesec etc., use book.
    – cfr
    Jul 27, 2017 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .