2

I need to modify my header. Now it looks like that: What I need to have: Where "DZIAŁ 1. PRZEPISY OGÓLNE" is a chapter, "Rozdział 2. Zasady ogólne" is a section and "Art 6-13" is a list of all subsections in section. Subsections are written as \subsection*{Art. 6 Zasada legalności} Is it even possible ? My code:

\documentclass[a4paper,12pt,twoside]{report}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{sectsty}
\usepackage{scrlayer-scrpage}
\pagestyle{scrheadings}
\renewcommand{\chaptermark}[1]{% 
\markboth{\space #1}{}}
\renewcommand{\sectionmark}[1]{
\markright{\thesection.\space #1}}%\hspace{0.5cm}}}
\begin{document}
\chapter{DZIAŁ I. PRZEPISY OGÓLNE}
\section{Rozdział 2. Zasady ogólne}
\subsection*{Art. 6 Zasada legalności }\noindent

\subsection*{Art. 7. Zasada uwzględniania interesu publicznego i słusznego interesu obywateli }

\subsection*{Art. 8. Zasada pogłębiania zaufania do organów państwa }\noindent

\subsection*{Art. 9. Obowiązek udzielania informacji faktycznej i prawnej stronom }\noindent

\subsection*{Art. 10. Zasada czynnego udziału stron w postępowaniu administracyjnym }\noindent

\subsection*{Art. 11. Zasada wyjaśniania zasadności decyzji lub postanowienia }\noindent

\subsection*{Art. 12. Zasada szybkości postępowania }\noindent

\subsection*{Art. 13. Załatwianie spornych spraw w drodze ugody administracyjnej }\noindent

\subsection*{Art. 14. Forma pisemna lub forma dokumentu elektronicznego }\noindent

\subsection*{Art. 15. Zasada dwuinstancyjności postępowania administracyjnego }\noindent

\subsection*{Art. 16. Zasady ogólne trybu odwoławczego }\noindent
\end{document} 
lockstep
  • 250,273
bartzmc
  • 111

1 Answers1

2

I have a solution to your problem, but the coding is pretty bad in my opinion. Though it works, I won't call this good code, just like a quickfix:

\documentclass[a4paper,12pt,twoside]{report}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{sectsty}
\usepackage{scrlayer-scrpage}

\pagestyle{scrheadings}

\lohead*{\rightmark}
\rohead*{\leftmark}
\lehead*{\rightmark}
\rehead*{\leftmark}
\renewcommand{\chaptermark}[1]{\markboth{\emph{\textbf{\Artborders}}}{#1}}
\renewcommand{\sectionmark}[1]{\markleft{#1~\emph{\textbf{\ArtBorders}}}}

\makeatletter
\IfFileExists{./\jobname.Art}{\input{\jobname.Art}}{}
\newwrite\ArtFile
\immediate\openout\ArtFile=\jobname.Art
\newcounter{Art@counter}
\newcommand{\Art}[2][]{%
    \ifx\relax#1\relax%
    \else%
        \setcounter{Art@counter}{\numexpr #1-1}%
    \fi%
    \refstepcounter{Art@counter}%
    \subsection*{Art.~\theArt@counter.~#2}%
    \ifcsname Art@firstC\roman{chapter}S\roman{section}\endcsname\else%
        \global\expandafter\edef\csname Art@firstC\roman{chapter}S\roman{section}\endcsname{\theArt@counter}%
    \fi%
    \expandafter\edef\csname Art@lastC\roman{chapter}S\roman{section}\endcsname{\theArt@counter}%
    \edef\@@Artfirst{\csname Art@firstC\roman{chapter}S\roman{section}\endcsname}%
    \edef\@@Artlast{\csname Art@lastC\roman{chapter}S\roman{section}\endcsname}%
    \immediate\write\ArtFile{%
        \expandafter\def\expandafter\noexpand\csname Art@markC\roman{chapter}S\roman{section}\endcsname{%
            \csname Art@firstC\roman{chapter}S\roman{section}\endcsname%
            \ifx\@@Artfirst\@@Artlast\else%
                -%
                \csname Art@lastC\roman{chapter}S\roman{section}\endcsname%
            \fi%
        }
    }
}
\newcounter{Art@counterbak}%
\newenvironment{subArts}[1][]{%
    \ifx\relax#1\relax%
        \setcounter{Art@counterbak}{\theArt@counter}%
    \else%
        \def\subArt@test{#1}%
        \def\subArt@string{step}%
        \ifx\subArt@test\subArt@string%
            \setcounter{Art@counterbak}{\numexpr\theArt@counter+1}%
        \else%
            \setcounter{Art@counterbak}{#1}%
        \fi%
    \fi%
    \setcounter{Art@counter}{0}%
    \renewcommand{\theArt@counter}{\arabic{Art@counterbak}\alph{Art@counter}}%
}{%
    \setcounter{Art@counter}{\theArt@counterbak}%
}
\newcommand{\ArtBorders}{%
    \ifcsname Art@markC\roman{chapter}S\roman{section}\endcsname%
        Art.~\csname Art@markC\roman{chapter}S\roman{section}\endcsname%
    \fi%
}
\AtEndDocument{\immediate\closeout\ArtFile}
\makeatother

\begin{document}
\chapter{DZIAŁ I. PRZEPISY OGÓLNE}
\section{Rozdział 2. Zasady ogólne}
%\thispagestyle{scrheadings}
\begin{subArts}[6]
\Art{Zasada legalności }\noindent
\Art{Zasada uwzględniania interesu publicznego i słusznego interesu obywateli }\noindent
\end{subArts}
\pagebreak
\Art{Zasada pogłębiania zaufania do organów państwa }\noindent
\pagebreak
\Art{Obowiązek udzielania informacji faktycznej i prawnej stronom }\noindent
\Art{Zasada czynnego udziału stron w postępowaniu administracyjnym }\noindent
\Art{Zasada wyjaśniania zasadności decyzji lub postanowienia }\noindent
\begin{subArts}
\Art{Zasada szybkości postępowania }\noindent
\Art{Załatwianie spornych spraw w drodze ugody administracyjnej }\noindent
\end{subArts}
\Art{Forma pisemna lub forma dokumentu elektronicznego }\noindent
\Art{Zasada dwuinstancyjności postępowania administracyjnego }\noindent
\begin{subArts}[step]
\Art{Zasady ogólne trybu odwoławczego }\label{art:zas}\noindent
\Art{test}
\Art{test2}\label{art:test2}
\end{subArts}
See Art. \ref{art:zas} and \ref{art:test2}.
\end{document} 

EDIT: Now you have the environment subArts, which accepts one optional argument. If no argument is given, it just uses the current counter value, if an argument is given and if that is the string step it increments the counter, else sets the counter to the given argument.

EDIT2: I think I got your headers right. But where do you want the pagenumbers?

EDIT3: The below code does roughly the same, but instead of printing into the .Art-file on each call of \Art, it only prints once for each \Art@mark, reducing the necessary prints drastically. I don't know, whether it is better to reduce unnecessary prints but use more variables or to reduce variable amount.

\documentclass[a4paper,12pt,twoside]{report}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{sectsty}
\usepackage{scrlayer-scrpage}

\pagestyle{scrheadings}

\lohead*{\rightmark}
\rohead*{\leftmark}
\lehead*{\rightmark}
\rehead*{\leftmark}
\renewcommand{\chaptermark}[1]{\markboth{\emph{\textbf{\ArtBorders}}}{#1}}
\renewcommand{\sectionmark}[1]{\markleft{#1~\emph{\textbf{\ArtBorders}}}}

\makeatletter
\newcount\Art@printcount
\Art@printcount=0
\newcount\Art@printpos
\Art@printpos=0
\def\Art@addprint{%
    \global\advance\Art@printcount by 1%
    \global\expandafter\edef\csname Art@printqueue\the\Art@printcount\endcsname{%
        C\roman{chapter}S\roman{section}%
    }%
}
\def\Art@print{%
    \loop\ifnum\Art@printcount>\Art@printpos%
    \advance\Art@printpos by 1%
    \edef\@@ArtcurCS{\csname Art@printqueue\the\Art@printpos\endcsname}
    \edef\@@Artfirst{\csname Art@first\@@ArtcurCS\endcsname}
    \edef\@@Artlast{\csname Art@last\@@ArtcurCS\endcsname}
    \immediate\write\ArtFile{%
        \expandafter%
        \def\expandafter\noexpand\csname Art@mark\@@ArtcurCS\endcsname{%
            \@@Artfirst%
            \ifx\@@Artfirst\@@Artlast\else%
                -%
                \@@Artlast%
            \fi%
        }%
    }%
    \repeat%
}

\IfFileExists{./\jobname.Art}{\input{\jobname.Art}}{}
\newwrite\ArtFile
\immediate\openout\ArtFile=\jobname.Art
\newcounter{Art@counter}[section]
\newcommand{\Art}[2][]{%
    \ifx\relax#1\relax%
    \else%
        \setcounter{Art@counter}{\numexpr #1-1}%
    \fi%
    \refstepcounter{Art@counter}%
    \subsection*{Art.~\theArt@counter.~#2}%
    \edef\@@ArtcurCS{C\roman{chapter}S\roman{section}}%
    \ifcsname Art@first\@@ArtcurCS\endcsname\else%
        \global\expandafter\edef\csname Art@first\@@ArtcurCS\endcsname{%
            \theArt@counter%
        }%
        \Art@addprint%
    \fi%
    \global\expandafter\edef\csname Art@last\@@ArtcurCS\endcsname{%
        \theArt@counter%
    }%
}
\newcounter{Art@counterbak}%
\newenvironment{subArts}[1][]{%
    \ifx\relax#1\relax%
        \setcounter{Art@counterbak}{\theArt@counter}%
    \else%
        \def\subArt@test{#1}%
        \def\subArt@string{step}%
        \ifx\subArt@test\subArt@string%
            \setcounter{Art@counterbak}{\numexpr\theArt@counter+1}%
        \else%
            \setcounter{Art@counterbak}{#1}%
        \fi%
    \fi%
    \setcounter{Art@counter}{0}%
    \renewcommand{\theArt@counter}{\arabic{Art@counterbak}\alph{Art@counter}}%
}{%
    \setcounter{Art@counter}{\theArt@counterbak}%
}
\newcommand{\ArtBorders}{%
    \ifcsname Art@markC\roman{chapter}S\roman{section}\endcsname%
        Art.~\csname Art@markC\roman{chapter}S\roman{section}\endcsname%
    \fi%
}
\AtEndDocument{\Art@print\immediate\closeout\ArtFile}
\makeatother

\begin{document}
\chapter{DZIAŁ I. PRZEPISY OGÓLNE}
\section{Rozdział 2. Zasady ogólne}
%\thispagestyle{scrheadings}
\begin{subArts}[6]
\Art{Zasada legalności }\noindent
\Art{Zasada uwzględniania interesu publicznego i słusznego interesu obywateli }\noindent
\end{subArts}
\pagebreak
\Art{Zasada pogłębiania zaufania do organów państwa }\noindent
\pagebreak
\Art{Obowiązek udzielania informacji faktycznej i prawnej stronom }\noindent
\Art{Zasada czynnego udziału stron w postępowaniu administracyjnym }\noindent
\Art{Zasada wyjaśniania zasadności decyzji lub postanowienia }\noindent
\begin{subArts}
\Art{Zasada szybkości postępowania }\noindent
\Art{Załatwianie spornych spraw w drodze ugody administracyjnej }\noindent
\end{subArts}
\Art{Forma pisemna lub forma dokumentu elektronicznego }\noindent
\Art{Zasada dwuinstancyjności postępowania administracyjnego }\noindent
\begin{subArts}[step]
\Art{Zasady ogólne trybu odwoławczego }\label{art:zas}\noindent
\Art{test}
\Art{test2}\label{art:test2}
\end{subArts}
See Art. \ref{art:zas} and \ref{art:test2}.
\chapter{test chapter}
\Art{the art of war}
\end{document} 
Skillmon
  • 60,462
  • Thanks a lot, it works fine but I need some changes. It accepts only a numbers? I have one section starting with 'Art. 66a' and I had to write it as a \subsection* because it was returning an error. screen – bartzmc Apr 17 '17 at 16:25
  • Yes, it only accepts a number because it uses a counter. You can set a \label because of that, which is nice, I think. I might have time later this day, then I could add the possibility for an alphabetic subcounter. – Skillmon Apr 17 '17 at 16:36
  • It's not necessary to modify this solution. It's a problem only when section start or ends with that. I don't know how to use \label in this case, can You explain? – bartzmc Apr 17 '17 at 17:32
  • When I'm using subArts environment I'm getting some kind of error but It compiles. It only works with putting 'a' symbol on subsection, the header starts as it was before "67-72". – bartzmc Apr 17 '17 at 18:18
  • 1
    Could you please post the warning message? Also, did you run LaTeX at least twice? This code needs two runs to set the header right. In my example above it puts '6-14c' into the header. – Skillmon Apr 17 '17 at 19:15
  • When I compile as LaTeX it shows no errors, but when I run PDFLaTeX it shows Error with no message. code, screen – bartzmc Apr 17 '17 at 19:31
  • 1
    I corrected the behavior inside of subArts, now the mark is set correct, even if the subArts is the first in a new section (only a missing `\gobal). See my edit. I don't get any errors using pdflatex. – Skillmon Apr 17 '17 at 19:36
  • Yep, it works now. Is it possible to fit in header yet chapter before section as I showed in question screen and put page number in bottom middle? – bartzmc Apr 17 '17 at 19:49
  • Another question, why I'm not getting header on first page after toc? I need it there to be. – bartzmc Apr 18 '17 at 06:43
  • 1
    That's because 1) you don't set up the plain.scrheadings style to use the marks set. For this you should use something like: \ihead*{\headmark} or \lohead*{\rightmark}\rehead*{\leftmark}, both resulting in roughly the same. And 2) even if you use the above code, on chapters the \rightmark will be empty, because the content of \rightmark matches the first used mark on that page which was empty due to your call of \markboth. For the second the only solution I found until now was to use \renewcommand{\chaptermark}{}, which doesn't result in the correct behavior, too. – Skillmon Apr 18 '17 at 09:18
  • 1
    @bartzmc If you want the counter of the Art. to reset to 0 after a new chapter, you might use: \newcounter{Art@counter}[chapter]. And if it should reset after a new section \newcounter{Art@counter}[section]. Just use those instead of the \newcounter{Art@counter} in the above code. – Skillmon Apr 18 '17 at 09:46
  • It works but in my document maybe margins are too wide and text is overlapping. In the other hand it might be risky when text will be longer it will not fit in header. Page numbers can be in middle bottom. screen – bartzmc Apr 18 '17 at 13:55
  • First solution with chapter name on left page and section, list of arts on right was better but still I'm getting no header on first page of chapter. It's not only after toc but also on first page of 2nd chapter. – bartzmc Apr 18 '17 at 14:39
  • 1
    You might use the following (generating two rows, if the title is too long): \ohead*{\rightmark\ \leftmark} \ihead*{} \chead*{} \cfoot*{\pagemark} instead of the other head-commands (like \lohead) – Skillmon Apr 18 '17 at 15:00
  • It looks good too, but would be better if section will appear in second line. How to get rid of blank space between header and chapter name? It's appearing only on first pages of new chapters. screen – bartzmc Apr 18 '17 at 15:20
  • @bartzmc If you want the section on right sides and the chapter on left sides you can use \rehead*{\rightmark} \lohead*{\leftmark} \ohead*{\pagemark} for the header setup. For the chapter in first line and the section in second line, use \ohead*{\rightmark\\\leftmark} instead of \ohead*{\rightmark\ \leftmark}. In this case you could also place the pagenumbers in the headline, using \ihead{\pagemark}, you might swap the \ohead and \ihead, though. – Skillmon Apr 18 '17 at 16:54
  • 1
    @bartzmc I think for the spacing you can google. This has to be answered somewhere as it's not that specific to your problem. – Skillmon Apr 18 '17 at 16:55
  • I use \raggedbottom before \begin{document} but this space does not disappearing. What about line breaking sectionmark from chaptermark? – bartzmc Apr 18 '17 at 17:52
  • @bartzmc I wrote the answer concerning line breaking sectionmark from chaptermark in the comment I gave over 1 hour ago: \ohead*{\rightmark\\\leftmark}. For the spacing, you'll have to search for 'reduce spacing before chapter headline'. First result: https://tex.stackexchange.com/a/63393/117050 use the second code snippet in egreg's answer. You don't need the titlesec-package for this. – Skillmon Apr 18 '17 at 18:01
  • Sorry I have missed it, now it looks clean. But this solution for blank space doesn't work. – bartzmc Apr 18 '17 at 18:19
  • It works in my code example above. You might ask a new question, if you can't solve this on your own (using the almighty help of google). – Skillmon Apr 18 '17 at 18:44