0

Hi this question is a follow up on a question regarding \leftskip that let me rethink my latex usage. David Carlisle says my usage of leftskip is wrong and i wold like to correct that...

So here is a mwe of my doc, wich in real is separated in different files, but that doesn't mater now. What i need is an advice how to clean up the file to work smoother.

    \documentclass{article}
    \usepackage[
    left={\dimexpr 10mm + 55pt},
    right=20mm,
    top=20mm,
    bottom=18mm,
    footskip=2em,
    headheight=2em,
    headsep=0.8em,
    showframe
    ]{geometry}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}   
    \usepackage{lipsum} 
    \usepackage{fancyhdr}
    \pagestyle{fancy} % --- new header
      \renewcommand{\headrulewidth}{0.1pt}  
      \renewcommand{\footrulewidth}{0.1pt}
      \setlength{\headheight}{16pt}  % --- new header end 
    \usepackage{tocloft}            %is alpha but it solves the indent on sectons
    \tocloftpagestyle{empty}
    \renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
      \makeatletter             %---------- start of @ sequencecontrollers ----------
        \renewcommand{\@tocrmarg}{15mm}                         %right margin
        \renewcommand{\@pnumwidth} {10mm}
        \renewcommand{\@dotsep}{4}
      \makeatother          %---------- end of @ sequencecontrollers ----------
    \renewcommand{\cftaftertoctitle}{\\[\baselineskip]\mbox{}\hfill{\footnotesize\scshape Seite}} %sets the word "page" upon the pagenumbers
    \setlength{\parskip}{0pt}      
    \setlength{\parindent}{0pt}                   
    \usepackage{titlesec}
    \titleformat{\section}
       {\normalfont\fontsize{17pt}{18pt}
       \selectfont\scshape}{\rlap{\thesection}}{55pt}{}
    \titlespacing{\section}{-55pt}{3.5ex plus 1ex minus .2ex}%
                                          {2.3ex plus.2ex}%
    \titleformat{\subsection}
       {\normalfont\fontsize{16pt}{17pt}
       \selectfont\scshape}{\rlap{\thesubsection}}{55pt}{}
    \titlespacing{\subsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                {1.5ex plus .2ex}%
    \titleformat{\subsubsection}
       {\normalfont\fontsize{15pt}{16pt}
       \selectfont\scshape}{\rlap{\thesubsubsection}}{55pt}{}
    \titlespacing{\subsubsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                      {1.5ex plus .2ex}%
    \titleformat{\paragraph}
       {\normalfont\fontsize{14pt}{15pt}
       \selectfont\scshape}{\rlap{\theparagraph}}{55pt}{} 
    \titlespacing{\paragraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                {1em}%
    \titleformat{\subparagraph}
       {\normalfont\fontsize{13pt}{14pt}
       \selectfont\scshape}{\rlap{\thesubparagraph}}{55pt}{}
    \titlespacing{\subparagraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                    {1em}%
    \setcounter{secnumdepth}{5} 
    \begin{document}
    \newgeometry{   % ------------- reset for centering -------------
    left=15mm,
    right=20mm,
    top=20mm,
    bottom=18mm,
    footskip=2em,
    headheight=2em,
    headsep=0.8em
    }
    \tableofcontents 
    \thispagestyle{empty}       
    \clearpage 
    \restoregeometry        % ------------- back to document setting (left+55pt)  -------------
    \setcounter{page}{1}    
    \section{One}
    \lipsum[1]
    \subsection{SubOne}
    \lipsum[2]
      \begin{figure}[!ht]
        \begin{flushright}
          \includegraphics[width=\linewidth]{example-image}
        \end{flushright}
      \end{figure}
    \section{two}
    \lipsum[3]
    \subsection{SubTwo}
      \begin{figure}[!ht]
        \begin{flushright}
          \includegraphics[width=\textwidth]{example-image}
        \end{flushright}
      \end{figure}
    \lipsum[4]
    \subsubsection{SubSubOne}
    \lipsum[5]
    \paragraph{ParOne}
    \lipsum[6]
    \subparagraph{SubParOne}
    \lipsum[7]
    \end{document} 

David says "it doesn't make a lot of sense to load geometry to set the page size and margins in a consistent way, then change settings such as \textwidth "by hand" just set the page format you want using geometry"

How can i make a page as in the MWE without seting these values by hand?

edit: The leftskip is solved with the help of John Kormylo (big thanks!) now only the Header need to go over the full width again...

short header sample

Let me add the wonderfull solution of John Kormylo here and ask two new questions regarding the new sample MWE:

        \documentclass{article}
    \usepackage[
    left=20mm,
    right=20mm,
    top=20mm,
    bottom=18mm,
    footskip=2em,
    headheight=2em,
    headsep=0.8em
    ]{geometry}
    \usepackage{filecontents}  %----------- i am adding a bibliography file ----------- 
    \begin{filecontents*}{main.bib}
    @Book{Goossens,
      author    = {Goossens, Michel and Mittelbach, Frank and 
                   Samarin, Alexander},
      title     = {The LaTeX Companion},
      edition   = {1},
      publisher = {Addison-Wesley},
      location  = {Reading, Mass.},
      year      = {1994},
    }
    @Book{adams,
      title     = {The Restaurant at the End of the Universe},
      author    = {Douglas Adams},
      series    = {The Hitchhiker's Guide to the Galaxy},
      publisher = {Pan Macmillan},
      year      = {1980},
    }
    \end{filecontents*}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}   
    \usepackage{lipsum} 
    \usepackage{paracol}
    \setlength{\columnsep}{0pt}
    \setcolumnwidth{55pt,{\dimexpr \textwidth-55pt}}
    \usepackage{fancyhdr}
    \pagestyle{fancy} % --- new header
      \renewcommand{\headrulewidth}{0.1pt}  
      \renewcommand{\footrulewidth}{0.1pt}
      \setlength{\headheight}{16pt}  % --- new header end 
    \usepackage{tocloft}            %is alpha but it solves the indent on sectons
    \tocloftpagestyle{empty}
    \renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
      \makeatletter             %---------- start of @ sequencecontrollers ----------
        \renewcommand{\@tocrmarg}{15mm}                         %right margin
        \renewcommand{\@pnumwidth} {10mm}
        \renewcommand{\@dotsep}{4}
      \makeatother          %---------- end of @ sequencecontrollers ----------
    \renewcommand{\cftaftertoctitle}{\\[\baselineskip]\mbox{}\hfill{\footnotesize\scshape Seite}} %sets the word "page" upon the pagenumbers
    \setlength{\parskip}{0pt}      
    \setlength{\parindent}{0pt}                   
    \usepackage{titlesec}
    \titleformat{\section}
       {\normalfont\fontsize{17pt}{18pt}
       \selectfont\scshape}{\rlap{\thesection}}{55pt}{}
    \titlespacing{\section}{-55pt}{3.5ex plus 1ex minus .2ex}%
                                          {2.3ex plus.2ex}%
    \titleformat{\subsection}
       {\normalfont\fontsize{16pt}{17pt}
       \selectfont\scshape}{\rlap{\thesubsection}}{55pt}{}
    \titlespacing{\subsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                {1.5ex plus .2ex}%
    \titleformat{\subsubsection}
       {\normalfont\fontsize{15pt}{16pt}
       \selectfont\scshape}{\rlap{\thesubsubsection}}{55pt}{}
    \titlespacing{\subsubsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                      {1.5ex plus .2ex}%
    \titleformat{\paragraph}
       {\normalfont\fontsize{14pt}{15pt}
       \selectfont\scshape}{\rlap{\theparagraph}}{55pt}{} 
    \titlespacing{\paragraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                {1em}%
    \titleformat{\subparagraph}
       {\normalfont\fontsize{13pt}{14pt}
       \selectfont\scshape}{\rlap{\thesubparagraph}}{55pt}{}
    \titlespacing{\subparagraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                    {1em}%
    \setcounter{secnumdepth}{5} 
     %----------- i am adding a bibliography here ----------- 
    \usepackage[backend=bibtex, style=numeric, defernumbers]{biblatex}
    \DeclareBibliographyCategory{skipbibliography}
    \DeclareCiteCommand{\cite}[\mkbibfootnote]
      {\usebibmacro{prenote}}
      {\addtocategory{skipbibliography}{\thefield{entrykey}}%
       \usedriver
         {\DeclareNameAlias{sortname}{default}}
         {\thefield{entrytype}}}
      {\multicitedelim}
      {\usebibmacro{postnote}}
    \usepackage{csquotes}
    \appto{\bibsetup}{\emergencystretch=1em}
    \addbibresource{main.bib}
     %----------- i am adding a index here----------- 
    \usepackage{imakeidx} 
    \makeindex[
    columns=3, 
    title=Alphabetischer Index, 
    options= -s latexfiles/style-index.tex]
     %----------- i am adding a glosssary here ----------- 
    \usepackage{glossaries}
    \makeglossaries 

    \newglossaryentry{latex}
    {
        name=latex,
        description={Is a mark up language specially suited 
        for scientific documents}
    }

    \newglossaryentry{maths}
    {
        name=mathematics,
        description={Mathematics is what mathematicians do}
    }

    \begin{document}  %----------- the document starts ----------- 
      \tableofcontents 
      \thispagestyle{empty}       
      \clearpage 
      \setcounter{page}{1}   
      \begin{paracol}{2}
        \switchcolumn
        \section{One}
          \lipsum[1]
        \subsection{SubOne}
          \lipsum[2]
          \cite{adams}   %----------- bib ----------- 
          \index{keyword}    %----------- index ----------- 
          \Gls{latex}       %----------- glosssary-----------
          \begin{figure}[!ht]
              \includegraphics[width=\linewidth]{example-image}
              \caption{Image SubOne}
          \end{figure}
        \section{two}
          \lipsum[3]
        \subsection{SubTwo}
          \begin{figure}[!ht]
              \includegraphics[width=\linewidth]{example-image}
              \caption{Image SubTwo}
          \end{figure}
          \lipsum[4]
          \cite{Goossens}   %----------- bib ----------- 
          \index{key}       %----------- index ----------- 
          \gls{maths}       %----------- glosssary-----------
        \subsubsection{SubSubOne}
          \lipsum[5]
           \begin{table}[htp]
              \centering
              \begin{tabular}{|l|p{9cm}|l|l|}\hline 
                Nr & desc & kriteria & priority \\ \hline 
                1 & A1 & T1 & M \\ \hline 
                2 & A2 & F2 & K1 \\ \hline 
                3 & A3 & T1 & M \\ \hline
                \multicolumn{4}{l}{* Legend: M = must, K1 = high, K2 = mid, K3 = low}
              \end{tabular} 
            \caption{Targets}
          \end{table}
        \paragraph{ParOne}
        \lipsum[6]
        \subparagraph{SubParOne}
        \lipsum[7]
        \newpage
          \section{References}  %----------- the document starts ----------- 
            \switchcolumn*
            \begin{column}
              \printbibliography%------------------ BIBLIOGRAPHY --------------------------------
              \listoffigures%------------------------- FIGURES ------------------------------------
              \listoftables%-------------------------- TABLES --------------------------------------
              \printindex%--------------------------- INDEX --------------------------------------
              \printglossaries%--------------------- GLOSSARY -----------------------------------
            \end{column}
      \end{paracol}
    \end{document} 

enter image description here

  • Read the geometry documentation. That's a good first step to learn how to use it. Some of the lengths however are not covered by geometry those you'll have to set by hand. But changing lengths just to change the value again is perhaps unnecessary (I'm talking about the lines \setlength{\parskip}{\baselineskip} and \setlength{\parskip}{0pt}). – Skillmon Dec 5 '17 at 20:50
  • \leftskip isn't so much wrong as simply incompatible with anything that resets it (like equation or itemize and apparently \section). OTOH, it is possible to move things outside the margins. – John Kormylo Dec 5 '17 at 21:41
  • BTW, \textwidth is set by geometry, so don't reset it. Use \linewidth for the space left after subtractng \leftskip (also automatic). – John Kormylo Dec 5 '17 at 21:44
1

Here is a way to achieve the same effect without using \leftskip. I tried to get the default vertical spacing from article class, but was confused by the use of negative values. (This would have been SO much easier without using titlesec!)

\documentclass{article}
\usepackage[
left={\dimexpr 20mm + 55pt},
right=20mm,
top=20mm,
bottom=18mm,
footskip=2em,
headheight=2em,
headsep=0.8em,
showframe
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}   
\usepackage{lipsum} 
%\leftskip=55pt                      
\setlength{\parskip}{\baselineskip}      
\setlength{\parindent}{0pt}             
  \setlength{\parskip}{0pt}
  %\setlength{\textwidth}{483pt}         
\usepackage{titlesec}
\titleformat{\section}
   {\normalfont\fontsize{17pt}{18pt}
   \selectfont\scshape}{\rlap{\thesection}}{55pt}{}
\titlespacing{\section}{-55pt}{3.5ex plus 1ex minus .2ex}%
                              {2.3ex plus.2ex}%
\titleformat{\subsection}
   {\normalfont\fontsize{16pt}{17pt}
   \selectfont\scshape}{\rlap{\thesubsection}}{55pt}{}
\titlespacing{\subsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                 {1.5ex plus .2ex}%
\titleformat{\subsubsection}
   {\normalfont\fontsize{15pt}{16pt}
   \selectfont\scshape}{\rlap{\thesubsubsection}}{55pt}{}
\titlespacing{\subsubsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                    {1.5ex plus .2ex}%
\titleformat{\paragraph}
   {\normalfont\fontsize{14pt}{15pt}
   \selectfont\scshape}{\rlap{\theparagraph}}{55pt}{} 
\titlespacing{\paragraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                {1em}%
\titleformat{\subparagraph}
   {\normalfont\fontsize{13pt}{14pt}
   \selectfont\scshape}{\rlap{\thesubparagraph}}{55pt}{}
\titlespacing{\subparagraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                {1em}%
\setcounter{secnumdepth}{5} 
\begin{document}
\section{One}
\lipsum[1]
\subsection{SubOne}
\lipsum[2]
  \begin{figure}[!ht]
      \includegraphics[width=\textwidth]{example-image}
  \end{figure}
\section{two}
\lipsum[3]
\subsection{SubTwo}
  \begin{figure}[!ht]
      \includegraphics[width=\textwidth]{example-image}
  \end{figure}
\lipsum[4]
\subsubsection{SubSubOne}
\lipsum[5]
\paragraph{ParOne}
\lipsum[6]
\subparagraph{SubParOne}
\lipsum[7]
\end{document} 

Here is the version not using titlesec. It may not look easier, but about I had to do was copy and paste.

I also had to change \@seccntformat to create the constant 55pt width section number.

\documentclass{article}
\usepackage[
left={\dimexpr 20mm + 55pt},
right=20mm,
top=20mm,
bottom=18mm,
footskip=2em,
headheight=2em,
headsep=0.8em,
showframe
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}   
\usepackage{lipsum} 

%\setlength{\parskip}{\baselineskip}      
\setlength{\parindent}{0pt}             
\setlength{\parskip}{0pt}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{-55pt}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\fontsize{17pt}{18pt}\selectfont\scshape}}
\renewcommand\subsection{\@startsection{subsection}{2}{-55pt}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\fontsize{16pt}{17pt}\selectfont\scshape}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{-55pt}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\fontsize{15pt}{16pt}\selectfont\scshape}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{-55pt}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\normalfont\fontsize{14pt}{15pt}\selectfont\scshape}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{-55pt}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\normalfont\fontsize{13pt}{14pt}\selectfont\scshape}}
\def\@seccntformat#1{\hbox to 55pt{\csname the#1\endcsname\hfil}}
\makeatother

\setcounter{secnumdepth}{5} 
\begin{document}
\section{One}
\lipsum[1]
\subsection{SubOne}
\lipsum[2]
  \begin{figure}[!ht]
      \includegraphics[width=\textwidth]{example-image}
  \end{figure}
\section{two}
\lipsum[3]
\subsection{SubTwo}
  \begin{figure}[!ht]
      \includegraphics[width=\textwidth]{example-image}
  \end{figure}
\lipsum[4]
\subsubsection{SubSubOne}
\lipsum[5]
\paragraph{ParOne}
\lipsum[6]
\subparagraph{SubParOne}
\lipsum[7]
\end{document} 

In this solution (based on the revised question), I use paracol to reduce the width by only using the right column. \textwidth refers to the whole page, while \columnwidth and \linewidth can be used for the reduced space.

\documentclass{article}
\usepackage[
left=20mm,
right=20mm,
top=20mm,
bottom=18mm,
footskip=2em,
headheight=2em,
headsep=0.8em
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}   
\usepackage{lipsum} 
\usepackage{paracol}
\setlength{\columnsep}{0pt}
\setcolumnwidth{55pt,{\dimexpr \textwidth-55pt}}
\usepackage{fancyhdr}
\pagestyle{fancy} % --- new header
  \renewcommand{\headrulewidth}{0.1pt}  
  \renewcommand{\footrulewidth}{0.1pt}
  \setlength{\headheight}{16pt}  % --- new header end 
\usepackage{tocloft}            %is alpha but it solves the indent on sectons
\tocloftpagestyle{empty}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
  \makeatletter             %---------- start of @ sequencecontrollers ----------
    \renewcommand{\@tocrmarg}{15mm}                         %right margin
    \renewcommand{\@pnumwidth} {10mm}
    \renewcommand{\@dotsep}{4}
  \makeatother          %---------- end of @ sequencecontrollers ----------
\renewcommand{\cftaftertoctitle}{\\[\baselineskip]\mbox{}\hfill{\footnotesize\scshape Seite}} %sets the word "page" upon the pagenumbers
\setlength{\parskip}{0pt}      
\setlength{\parindent}{0pt}                   
\usepackage{titlesec}
\titleformat{\section}
   {\normalfont\fontsize{17pt}{18pt}
   \selectfont\scshape}{\rlap{\thesection}}{55pt}{}
\titlespacing{\section}{-55pt}{3.5ex plus 1ex minus .2ex}%
                                      {2.3ex plus.2ex}%
\titleformat{\subsection}
   {\normalfont\fontsize{16pt}{17pt}
   \selectfont\scshape}{\rlap{\thesubsection}}{55pt}{}
\titlespacing{\subsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                            {1.5ex plus .2ex}%
\titleformat{\subsubsection}
   {\normalfont\fontsize{15pt}{16pt}
   \selectfont\scshape}{\rlap{\thesubsubsection}}{55pt}{}
\titlespacing{\subsubsection}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                  {1.5ex plus .2ex}%
\titleformat{\paragraph}
   {\normalfont\fontsize{14pt}{15pt}
   \selectfont\scshape}{\rlap{\theparagraph}}{55pt}{} 
\titlespacing{\paragraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                            {1em}%
\titleformat{\subparagraph}
   {\normalfont\fontsize{13pt}{14pt}
   \selectfont\scshape}{\rlap{\thesubparagraph}}{55pt}{}
\titlespacing{\subparagraph}{-55pt}{3.25ex plus 1ex minus .2ex}%
                                                {1em}%
\setcounter{secnumdepth}{5} 
\begin{document}
\tableofcontents 
\thispagestyle{empty}       
\clearpage 
\setcounter{page}{1}   
\begin{paracol}{2}
\switchcolumn
\section{One}
\lipsum[1]
\subsection{SubOne}
\lipsum[2]
  \begin{figure}[!ht]
      \includegraphics[width=\linewidth]{example-image}
  \end{figure}
\section{two}
\lipsum[3]
\subsection{SubTwo}
  \begin{figure}[!ht]
      \includegraphics[width=\linewidth]{example-image}
  \end{figure}
\lipsum[4]
\subsubsection{SubSubOne}
\lipsum[5]
\paragraph{ParOne}
\lipsum[6]
\subparagraph{SubParOne}
\lipsum[7]
\end{paracol}
\end{document} 
  • Can you add a sample wthout Titlesec? I don‘t remember why i added titlesec so i will try without. – novski Dec 6 '17 at 7:11
  • Titlesec is a logical choice to create a new section title. I prefer to copy and modify the original code from article.cls. – John Kormylo Dec 6 '17 at 16:51
  • ok thanks a lot. I just realized that i forgot to mention the toc that now is shifted +55pt right as well. I found the \newgeometry{left=20mm} but i would rather like to find a \newgeometry{left=\defaultvalue} or something similar. Does that exist? – novski Dec 6 '17 at 21:10
  • An other not so nice thing is that the header and footer is now not over the section numberings it starts with the text... – novski Dec 6 '17 at 21:21
  • I just added another solution using paracol. – John Kormylo Dec 6 '17 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.