2

The following LaTeX code works fine on my laptop, but doesn't on my friend's computer. We are both using Texmaker. The problem seems to be the section command, which gives me the error message: "Missing number, treated as zero" and "Illegal unit of measure (pt inserted)"

\documentclass[12pt,DIV = 15, titlepage,bibtotoc]{scrreprt}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fourier,avant}
\usepackage[pdftex]{graphicx}
\usepackage[font=footnotesize,bf,sf]{caption}
\usepackage[onehalfspacing]{setspace}
\parindent0pt
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{wallpaper}
\usepackage{hyperref}
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}

\usepackage{titlesec, blindtext, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\huge\bfseries}


\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[L]{\leftmark}
\fancyhead[R]{\rightmark}
\cfoot{\thepage} 




\begin{document}
\chapter{works}
\subsection*{Doesn't}
Why not?
\end{document}

What could be the problem here?

  • 2
    titlesec and fancyhdr and KOMA --- oh my ;-) – user31729 May 1 '16 at 18:23
  • it gives an error in texlive 2016 presumably your laptop has older versions of one or more of the packages. – David Carlisle May 1 '16 at 18:25
  • 1
    Removing titlesec (and \titleformat) will cure the problem, but don't use fancyhdr with KOMA or drop KOMA. hyperref should be the last package to be loaded here, not somewhere in between – user31729 May 1 '16 at 18:27
  • 2
    Update!!!!!!!!!! – Johannes_B May 1 '16 at 18:33
5

Do not use package titlesec together with a KOMA-Script class. It is possible to get the same format of the chapter heading using KOMA-Script commands.

\renewcommand\chapterformat{%
  \thechapter\hspace*{20pt}\textcolor{gray75}{|}\hspace*{20pt}%
}
\addtokomafont{chapter}{\Huge\rmfamily}

Additional remarks:

  • Use the new syntax for option bibliography=totoc.
  • Remove option pdftex for package graphicx.
  • If there should be a \parskip instead \parindent to mark new paragraphs use the class option parskip with one of the values full, half etc. (see the KOMA-Script documentation).
  • There is no need to load package caption in your example. You can change the font of the captions and their labels using \addtokomafont or \setkomafont.
  • hyperref should be the last package.

enter image description here

Code:

\documentclass[12pt,DIV = 15,titlepage,
  bibliography=totoc % <- changed syntax
]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fourier,avant}
\usepackage{graphicx} % <-remove option pdftex
\usepackage[onehalfspacing]{setspace}
\setlength{\parindent}{0pt} % <- do really want no paragraph mark?
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{wallpaper}

\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}

\usepackage{color}
\definecolor{gray75}{gray}{0.75}

\renewcommand\chapterformat{%
  \thechapter\hspace*{20pt}\textcolor{gray75}{|}\hspace*{20pt}%
}
\addtokomafont{chapter}{\Huge\rmfamily}

\addtokomafont{caption}{\footnotesize}% <- instead using package caption
\addtokomafont{captionlabel}{\bfseries\sffamily}% <- <- instead using package caption

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[L]{\leftmark}
\fancyhead[R]{\rightmark}
\cfoot{\thepage} 

\usepackage{blindtext}% dummy text
\usepackage{hyperref}% last package

\begin{document}
\chapter{works}
\subsection*{Doesn't}
Why not?
\begin{figure}[htb]
  \centering
  \rule{3cm}{2cm}%
  \caption{A caption}%
\end{figure}
\blinddocument
\end{document}

Note that if you are using fancyhdr with a KOMA-Script class, you have to redefine \fancyhead and \fancyfoot (like in your code) to remove the old font commands like \sl etc.

But the recommended package for headers and footers in a KOMA-Script document is scrlayer-scrpage.

\documentclass[12pt,DIV = 15,titlepage,
  bibliography=totoc % <- changed syntax
]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fourier,avant}
\usepackage{graphicx} % <-remove option pdftex
\usepackage[onehalfspacing]{setspace}
\setlength{\parindent}{0pt} % <- do really want no paragraph mark?
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{wallpaper}

\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}

\usepackage{color}
\definecolor{gray75}{gray}{0.75}

\renewcommand\chapterformat{%
  \thechapter\hspace*{20pt}\textcolor{gray75}{|}\hspace*{20pt}%
}
\addtokomafont{chapter}{\Huge\rmfamily}

\addtokomafont{caption}{\footnotesize}% <- instead using package caption
\addtokomafont{captionlabel}{\bfseries\sffamily}% <- <- instead using package caption

\usepackage[autooneside=false,automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\rightmark}
\cfoot*{\pagemark}
\addtokomafont{pageheadfoot}{\upshape}
\renewcommand\chaptermarkformat{}
\renewcommand\sectionmarkformat{}

\usepackage{blindtext}% dummy text
\usepackage{hyperref}
\begin{document}
\chapter{works}
\subsection*{Doesn't}
Why not?
\begin{figure}[htb]
  \centering
  \rule{3cm}{2cm}%
  \caption{A caption}%
\end{figure}
\blinddocument
\end{document}

Maybe you can remove package wallpaper too because you can define an additional layer to use a background image.


If you really want to use titlesec together with a KOMA-Script class and you have the titlesec version 2.10.2 then you must install the prerelease of KOMA-Script 3.20. If your titlesec is version 2.10.1 you have to update this package too.

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.