Text Formattingunexpected linebreak with makebox

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
macjo16
Posts: 1
Joined: Fri Nov 22, 2019 1:31 pm

unexpected linebreak with makebox

Post by macjo16 »

Hi, I think the picture explains my Problem:
Image

The chapter enumeration on odd pages should behave the same as all other titles (e.g. subtitle on picture).
Can´t figure out why it is not working. Maybe someone has an idea?

Here´s my code:
\documentclass[twoside]{scrreprt}
\usepackage{blindtext}

% Align titles to outer side
\renewcommand*{\raggedsection}{\ifthispageodd{\raggedleft}{\raggedright}}

% Push section enumeration outward
\renewcommand*{\sectionlinesformat}[4]{%
  \ifthispagewasodd
    #4\makebox[0pt][l]{\hskip\marginparsep #3}%
  \else
    \makebox[0pt][r]{#3\hskip\marginparsep}#4%
  \fi
}

% Push chapter enumeration outward 
\makeatletter
\renewcommand*{\chapterlinesformat}[3]{%
    \ifthispagewasodd
        #3\makebox[0pt][l]{\hskip\marginparsep #2}%  % THAT LINE WILL NOT WORK!!!
    \else
        \makebox[0pt][r]{#2\hskip\marginparsep}#3%
    \fi
}
\makeatother

\renewcommand*{\chapterformat}{\thechapter\autodot}
\renewcommand*{\sectionformat}{\thesection\autodot}
\renewcommand*{\subsectionformat}{\thesubsection\autodot}
\renewcommand*{\subsubsectionformat}{\thesubsubsection\autodot}

\begin{document}
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\chapter{Another Chapter}
\subsection{Subsection}
\blindtext
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

unexpected linebreak with makebox

Post by rais »

That't because the title argument to \chapterlinesformat (#3) contains an internal paragraph break, hence the new line.
Since you want to put the number into the margin, try

Code: Select all

\renewcommand*{\chapterlinesformat}[3]{%
  #3\marginline{\usekomafont{disposition}\usekomafont{chapter}#2}%
}
You don't need to enclose it by \makeatletter/\makeatother.

KR
Rainer
Post Reply