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} 
6
  • 2
    At least one question I can answer: It is possible. But the solution (well at least a plan to a solution) which comes to my mind might exceed my skill :)
    – Skillmon
    Apr 17, 2017 at 6:48
  • Crosspost
    – Johannes_B
    Apr 17, 2017 at 7:21
  • 2
    Is there any reason why you use unnumbered subsections, whereas each subsection title contains a counter?
    – Bernard
    Apr 17, 2017 at 8:44
  • Because it was easier to write it manually than rename subsection as 'Art. " but if it's needed to put this in header it can be changed.
    – bartzmc
    Apr 17, 2017 at 9:58
  • 1
    Have a look at this. It contains the answer for you.
    – TeXnician
    Apr 17, 2017 at 10:13

1 Answer 1

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} 
21
  • 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, 2017 at 19:15
  • 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, 2017 at 19:36
  • 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, 2017 at 9: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, 2017 at 9:46
  • 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, 2017 at 15:00

You must log in to answer this question.

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