1

I have a relatively simple LaTeX document with a few sections and subsections and everything would be fine, BUT: I would like to have a custom designed titlepage for every section. (btw. MWE at the bottom!) My TOC looks like this:

enter image description here

Right now, the page with a new section (e.g. 2 A second...) looks like this:

enter image description here

But I rather would like to have something that stands out! This is my idea, how I would like to see e.g. section 2:

enter image description here

You find a MWE is below!

My question now is: How can I create these nice looking title pages for my sections? I think there are some possibilities with the titlesec package. But I'm not good in trying it myself. Can anybody help me with this? Any help is very much appreciated!

\documentclass[%
a4paper,
11pt,
headsepline,
footsepline,
]
{scrartcl}


\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{booktabs}                           
\usepackage{amsmath}                            
\usepackage{tabularx}
\usepackage{seqsplit}
\usepackage{longtable}                      
\usepackage{wrapfig}
\usepackage{ulem}                   
\usepackage[version=3,arrows=pgf]{mhchem}
\usepackage[pdf]{pstricks}
\usepackage{acronym}
\usepackage{wasysym}            
\usepackage{rsphrase}                       
\usepackage{siunitx}                        
\usepackage{tikz}                           
\usepackage{float}
\usepackage{geometry}
\geometry{bottom=3.5cm}
\geometry{top=3.5cm}
\geometry{left=2.5cm}
\geometry{right=2.5cm}
\usepackage{enumerate}                          
\usepackage{multirow}
\usepackage{lscape}
\usepackage{rotating}
\usepackage{subfigure}
\usepackage{url}
\usepackage{setspace}
\usepackage{threeparttable}
\usepackage{array} 
\usepackage{graphicx}
\usepackage[labelfont=bf,format=plain]{caption}
\usepackage[linkcolor=black,citecolor=black]{hyperref}
\makeatletter
\@addtoreset{figure}{section}
\@addtoreset{table}{section}
\makeatother 
\renewcommand{\thefigure}{\thesection.\arabic {figure}}
\renewcommand{\thetable}{\thesection.\arabic{table}}    

\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\setcounter{tocdepth}{3}   
\setcounter{secnumdepth}{3}  

\sisetup{%
    obeyall,            
    per=frac,               
    decimalsymbol=comma,    
    unitmode=text   
    }

\hbadness=10000
\vbadness=10000
\hyphenpenalty=100000
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\linespread{1.25}

\begin{document}
\sloppy
\thispagestyle{empty}

\LARGE
\vspace{0.5cm}

\begin{center} \LARGE 
\textbf{\LARGE XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\}
\textbf{\LARGE XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\}
\end{center}
\vspace{1.0cm}

\begin{center}
\Large
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
\end{center}
\vspace{1.0cm}

\begin{table}[!h]
\Large
\begin{tabular}{ll}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX & \\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX& \\
\end{tabular}
\normalsize
\end{table}

\vspace{0.5cm}
\begin{table}[!b]
\Large
\begin{tabular}{ll}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXh\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\
v & \\
\end{tabular}
\normalsize
\end{table}
\normalsize

\clearpage
\thispagestyle{empty}

\setcounter{page}{1}
\pagenumbering{Roman}

\clearpage
\thispagestyle{plain}

\section*{section X}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX \\

\large
\paragraph{XXXXXXXXXXXXXXXXXXXXXXXXXXXXX}

\clearpage  
\thispagestyle{empty}

\phantom{oben}
\phantom{oben}
\phantom{oben}
\phantom{oben}
\phantom{oben}
\phantom{oben}
\phantom{oben}
\phantom{oben}
\phantom{oben}

\begin{flushright} \LARGE 
\textbf{\LARGE It will be fine.\\}
\end{flushright}
\vspace{1.0cm}

\clearpage
\thispagestyle{plain}
\tableofcontents

\clearpage
\listoffigures
\addcontentsline{toc}{section}{List of Figures}

\clearpage
\listoftables
\addcontentsline{toc}{section}{List of Tables}
\clearpage

\clearpage
\section*{some other hidden chapter}
XXXXXXXXXXXXXXXXXXXXXXXXXXXX

\clearpage
\setcounter{page}{1}
\pagenumbering{arabic}
\section{A first very nice and fancy looking title}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 

\subsection{subsectionn 1-1}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 

\subsection{subsectionn 1-2}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 

\subsubsection{subsubsection 1-2-1}

%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\section{A second very nice and fancy looking title}

\subsection{subsection 2-1}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

\subsection{subsection 2-2}

\subsubsection{subsubsection 2-2-1}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

\subsubsection{subsubsection 2-2-1}

\subsection{subsection 2-3}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\section{A third very nice and fancy looking title}

\subsection{subsection 3-1}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

\subsection{subsection 3-2}

\subsubsection{subsubsection 3-2-1}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

\subsubsection{subsubsection 3-2-1}

\subsection{subsection 3-3}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

\end{document}
  • 5
    Your example is far from minimal. Is it possible to compress it a bit? – TeXnician Feb 24 '17 at 22:02
  • 5
    titlesec and KOMA is a bad combination – user31729 Feb 24 '17 at 22:08
  • 1
    geometry and KOMA isn't a great choice, either. (Not as bad as titlesec and KOMA.) – cfr Feb 25 '17 at 1:18
  • 3
    @cfr geometry is the package of choice with KOMA script if fixed margins are to be defined. – Johannes_B Feb 25 '17 at 7:13
  • 2
    If i was in your spot, i would stop scavenging old google results for some valuable content and read a recent LaTeX introduction. You code is a mess, not even mentioning using a documentclas that is not supposed to do what you want. – Johannes_B Feb 25 '17 at 7:19
3

Here is a solution in which I patched the \section command to get the desired formatting. The additional data, i.e. the "Here comes a small text..." part in your example picture is gathered via \sectionpreamble right before issuing the \section command:

\sectionpreamble{%
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  At vero eos et accusam et justo duo dolores et ea rebum.
  Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  At vero eos et accusam et justo duo dolores et ea rebum.
  Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
}
\section{There will be a very long title here that spans lots and lots and lots and lots and lots of lines}

The complete code would be:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{xcolor}

\makeatletter
\newdimen\thesectionwdmax
\newdimen\sectiontitlewd
\AtBeginDocument{%
  \setbox0=\hbox{\scalebox{5}{99}}
  \thesectionwdmax\wd0
  \sectiontitlewd\dimexpr\textwidth-\thesectionwdmax-2.25cm\relax
}
\def\section{\par
   \addvspace{4ex}%
   \@afterindentfalse
   \secdef\@sec\@ssec}
\def\@sec[#1]#2{%
    \ifnum \c@secnumdepth>\m@ne
      \refstepcounter{section}%\@maybeasf%
       \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
    \else
      \addcontentsline{toc}{section}{#1}%
    \fi
    {\parindent\z@
     \raggedright
     \interlinepenalty \@M
     \thispagestyle{empty}
     \normalfont
     \setbox0=\vbox{\parbox{\sectiontitlewd}{\noindent\huge#2}}
     \sectfont
     \raisebox{-1em}{\parbox[c]{\thesectionwdmax}{\noindent\null\hfill\scalebox{5}{\thesection}}}
     \hspace{.25cm}
     \raisebox{1em}{\parbox[t][\dimexpr\ht0+\dp0\relax]{1em}{\leaders\vrule\vfill}}
     \hspace{1cm}
     \parbox[t]{\sectiontitlewd}{\noindent\huge#2}
     \vfill\printsectionpreamble\vfill
     \sectionmark{}\par}%
     \nobreak
    \@afterheading
    \clearpage}
\def\@ssec#1{%
    {\parindent\z@
     \raggedright
     \interlinepenalty \@M
     \thispagestyle{empty}
     \sectfont #1
     \vfill\printsectionpreamble\vfill
     \sectionmark{}\par}%
     \nobreak
     \vskip 3ex
    \@afterheading
    \clearpage}
\def\printsectionpreamble{%
  \ifx\currentsecpreamble\empty\else
    \colorbox{pink}{\parbox{\textwidth}{\normalfont\normalsize\currentsecpreamble}}\fi
  \let\currentsecpreamble\empty}
\def\sectionpreamble#1{\gdef\currentsecpreamble{#1}}
\makeatother

\begin{document}
\sectionpreamble{%
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  At vero eos et accusam et justo duo dolores et ea rebum.
  Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  At vero eos et accusam et justo duo dolores et ea rebum.
  Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
}
\section{There will be a very long title here that spans lots and lots and lots and lots and lots of lines}
%...
\end{document}

output

  • WOW thats almost it! Two small things though: 1) how can I confine the design of the seperate titlepages to only e.g. section 2 and 3 (even, if I have 5+ sections) 2) Can I set the title left aligned? – AndreH Feb 25 '17 at 11:08
  • @AndreH -- 1) just define a distinct macro, say \AndreHsection \mysection or \titlepagedsection or whatever instead of redefining \section (i.e. see the line \def\section...); 2) the title is left aligned. Beeing Completely left it will clip with the section number and the vertical line. You can reduce the space between the line and the title tho. – Ruben Feb 25 '17 at 11:13
  • 1
    You should not patch \section. Simply redefine \sectionlinesformat. – Schweinebacke Mar 1 '17 at 10:07
  • This is it, i managed to get all titlepages right :-) Thank you so much! – AndreH Mar 4 '17 at 8:42
3

Here is a suggestion redefining the KOMA-Script command \sectionlinesformat:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{xcolor}

\newdimen\thesectionwdmax
\newdimen\sectiontitlewd
\AtBeginDocument{%
  \setbox0=\hbox{{\usekomafont{disposition}\usekomafont{section}\scalebox{2}{99}}}%
  \thesectionwdmax\wd0%
  \sectiontitlewd\dimexpr\textwidth-\thesectionwdmax-.75cm-1pt\relax
}

\renewcommand\sectionformat{\protect\scalebox{2}{\thesection}}
\addtokomafont{section}{\huge}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}
    {\ifstr{#3}{}
      {\@hangfrom{\hskip #2#3}{#4}}
      {%
        \begin{tabular}{@{}r@{\hspace{.25cm}\vrule width 1pt\hspace{.5cm}}l@{}}
        \parbox{\thesectionwdmax}{\centering#3}%
        &%
        {\parbox{\sectiontitlewd}{\raggedright#4}}%
        \end{tabular}%
      }%
    }
    {\@hangfrom{\hskip #2#3}{#4}}%
}

\newcommand\sectionpreamble[1]{{%
  \vfill
  \setlength\fboxsep{2em}%
  \colorbox{lightgray}{%
    \parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}
      {\raggedright #1}%
  }%
  \vfill
  \clearpage
}}
\makeatother

\usepackage{lipsum}
\begin{document}
\tableofcontents
\section{There will be a very long title here that spans lots and lots and lots and lots and lots of lines}
\lipsum[1]
\section{A short title}
\lipsum[2]

\clearpage
\section{There will be a very long title here that spans lots and lots and lots and lots and lots of lines}
\sectionpreamble{\lipsum[1]}
\lipsum[5-6]

\section{Another section}
\lipsum
\addsec{Unnumbered section}
More text ...
\end{document}

enter image description here

  • Oh this is also VERY nice! I actually learned a lot from your code. I'm now done with my document, but I will keep this answer also in my bookmarks! Thank you very much! :-) – AndreH Mar 4 '17 at 8:44

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.