Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have been googleing for several hours now, my goal is to have the same indent for each chapter/section. Meaning there is the number but every chapter starts for example at 3cm from the left margin. Do you know what I mean? :)

I am using the titlesec package to customize fontsize, color and so on but I havent managed to get the spacing right. Therefore I tried to do it with two parboxes like that:

    \titleformat{\section}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\parbox{1cm}{\flushleft\thesection}{\parbox{6cm}{\flushleft #1}}}
      [\vspace*{5pt}]

If the chapter title is now doublespaced it looks really ugly and LaTeX just throws the parboxes around..

Do you guys know how to do it so every chapter/section/subsection starts at the same point?

share|improve this question
1  
Which exactly is the desired result? When you say "chapter/sectiom/subsection starts at the same point" do you mean the numbering must be flushed to the margin, but the titles should all be aligned at some predefined distace from the margin? How are the chapter heading expected to be? –  Gonzalo Medina Jun 20 '13 at 15:14
    
Welcome to TeX.SX! Usually it is preferable to provide a complete minimal working example (MWE). –  mafp Jun 20 '13 at 15:29

2 Answers 2

up vote 3 down vote accepted

Your idea is good, but you only have to use the appropriate lengths. If the box for the numbers has width x then the box for the titles has to have width equal to \textwidth-x. In the following example, for the numbers I used a \makebox of width \mylena (initially set to 1.5cm) and for the titles a \parbox with \raggedright contents and width \mylenb=\textwidth-\mylena. I used some definitions based on your snippet, but of course you can use your settings (notice that you'll need two separate, yet similar, definitions: one for numbered units and the other, for the unnumbered ones (through the numberless key)):

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}

\newlength\mylena
\newlength\mylenb
\setlength\mylena{1.5cm}
\setlength\mylenb{\dimexpr\textwidth-\mylena\relax}

\newcommand\PlaceNumber[1]{%
  \makebox[\mylena][l]{#1}}

\colorlet{pt_Blau_04}{cyan!60!black}

\titleformat{\chapter}
      {\color{pt_Blau_04}\huge\sffamily\bfseries}
      {}
      {0em}
      {\PlaceNumber{\thechapter}\parbox[t]{\mylenb}{\raggedright#1}}
\titleformat{name=\chapter,numberless}
      {\color{pt_Blau_04}\huge\sffamily\bfseries}
      {}
      {0em}
      {\PlaceNumber{}\parbox[t]{\mylenb}{\raggedright#1}}
\titleformat{\section}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\PlaceNumber{\thesection}\parbox[t]{\mylenb}{\raggedright#1}}
      [\vspace*{5pt}]
\titleformat{name=\section,numberless}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\PlaceNumber{}\parbox[t]{\mylenb}{\raggedright#1}}
      [\vspace*{5pt}]
\titleformat{\subsection}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\PlaceNumber{\thesubsection}\parbox[t]{\mylenb}{\raggedright#1}}
\titleformat{name=\subsection,numberless}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\PlaceNumber{}\parbox[t]{\mylenb}{\raggedright#1}}

\begin{document}

\chapter{Test Chapter with some additional text to see the indentation}
\section{Test Numbered Section}
\section*{Test Unnumbered Section}
\subsection{Test Numbered  Subsection}
\subsection*{Test Unnumbered  Subsection}

\end{document}

enter image description here

share|improve this answer

If you don't plan to have paragraph breaks in your chapter and section titles (which you shouldn't anyway), here's a simpler set of macros without doing measurements:

\documentclass{book}
\usepackage{titlesec}
\usepackage{xcolor}

\newlength\numberwidth
\setlength\numberwidth{1.5cm}

\newcommand\dotitle[2]{%
  \parbox{\textwidth}{
    \raggedright
    \hangindent\numberwidth\hangafter1
    \makebox[\numberwidth][l]{#1}#2%
  }%
}

\colorlet{pt_Blau_04}{cyan!60!black}

\titleformat{\chapter}
      {\color{pt_Blau_04}\huge\sffamily\bfseries}
      {}
      {0em}
      {\dotitle{\thechapter}}
\titleformat{name=\chapter,numberless}
      {\color{pt_Blau_04}\huge\sffamily\bfseries}
      {}
      {0em}
      {\dotitle{}}
\titleformat{\section}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\dotitle{\thesection}}
      [\vspace*{5pt}]
\titleformat{name=\section,numberless}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\dotitle{}}
      [\vspace*{5pt}]
\titleformat{\subsection}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\dotitle{\thesubsection}}
\titleformat{name=\subsection,numberless}
      {\color{pt_Blau_04}\large\sffamily\bfseries}
      {}
      {0em}
      {\dotitle{}}

\begin{document}

\chapter{Test Chapter with some additional text to see the indentation}
{\let\cleardoublepage\relax % just to make the example fit in one page
 \chapter*{Test unnumbered chapter}
}
\section{Test Numbered Section}
\section*{Test Unnumbered Section}
\subsection{Test Numbered  Subsection}
\subsection*{Test Unnumbered  Subsection}

\end{document}

I use the \hangindent and \hangafter feature of TeX. The \dotitle command has two arguments, the second is the sectional title, as usual with titlesec.

enter image description here

share|improve this answer
    
wow thank you :) it quite smart to do it the relative way ;-) –  Kathiieee Jun 20 '13 at 19:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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