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 know this subject has been mentioned before, but I'm still having a problem in creating a space under a section title. I used the titlesec package and then tried using the command \titlespacing{\section}...

This is my code. Can anybody help?

\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage[compact]{titlesec}
\usepackage{setspace}
\usepackage{sectsty}
\chapterfont{\huge}
\sectionfont{\Huge}
\begin{document}
\chapter*{Kapitel 1}
\section*{Einleitung}
\begin{large}
\subsection*{1.1 Motivation}
share|improve this question
1  
Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. –  Claudio Fiandrino Apr 14 '13 at 13:05
    
Your given code is not compiling. Have you tested it? Please make it running. What should \begin{large} do? Do you want there a greater space? Package blindtext helps you to include a little dummy text. See on CTAN. –  Kurt Apr 14 '13 at 13:33
    
Thanks! But sorry I didn't get what you mean. So leave the titlespacing and just use the \\ to make the spaces? –  abdu Apr 14 '13 at 13:56
    
@user29019 but exactly what kind of space are you trying to get? Exactly how much space do you want after \chapter and \section? –  Gonzalo Medina Apr 14 '13 at 14:55
    
@GonzaloMedina yes I tried it, it works. The \begin{large} is for the font size of the text. So everything is working till now. But I need create a titlespacing under the 'Einleitung' so between the section title und the text beneath it. I'm a new LaTeX user, I'm writing a scientific thesis. so there would be chapters, section and subsections. I searched in the internet for packages and commands I found things like \vspace, \titlespacing{\section}... but non of them worked, I compile the .tex file through a terminal (ubuntu) but I get no changes. –  abdu Apr 14 '13 at 16:16

2 Answers 2

up vote 5 down vote accepted

Using the titlesec package you can use \titlespacing* you can change the spacing before and after the title; the syntax of the command is:

\titlespacing*{<command>}{<left>}{<before-sep>}{<after-sep>}

(there's an additional optional argument, but it's not important here). <left> increases the left margin; <before-sep> controls the vertical space before the title; <after-sep> controls the vertical space after the title. (Please refer to the package documentation for further information). A complete example:

\documentclass[10pt]{book}
\usepackage{titlesec}
\usepackage{lipsum}% just to generate text for the example

\titlespacing*{\section}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}

\begin{document}

\chapter{Kapitel 1}
\lipsum[4]
\section{Einleitung}
\lipsum[4]
\subsection{Motivation}
\lipsum[4]

\end{document}

enter image description here

I used ex (approximately the height of an "x" in the current font) as the unit for the lengths used, but you can use instead any other valid LaTeX unit (cm, in, mm, pt, among others); you can also use multiples of predefined lengths such as \baselineskip:

\titlespacing*{\subsection}
  {0pt}{2\baselineskip}{3\baselineskip}

I used ex since in this way the space is font-dependent. If you want to change the formatting of the titles, you can also use the same package and its powerful \titleformat command.

share|improve this answer
    
thanks very much! Everything worked, so now I know that I only have to use the titlesec package. I used the cm unit to change the spacing before the chapter and it worked! However I still have a problem, the one with the error. I can ignore it but it bothers while compiling through the terminal. I usually seperate two paragraphs with \\ \\ and this makes the error I think. Is there a way I can seperate paragraphs? –  abdu Apr 15 '13 at 11:08
    
@abdu Yes, using two consecutive \\ commands will result in errors. You can use \par\bigskip instead at the end of each paragraph. Another option would be to load the parskip package which automatically suppresses indentation and increases separation between paragraphs. Yet another option would be to switch to the document class scrreprt and use its parskip features. –  Gonzalo Medina Apr 15 '13 at 12:49
    
\pas\bigskip worked. I tried the parskip package by defining the skip length: \setlength{\parskip}{0pt} and then typing \parskip between the paragraphs, but I got errors while compiling. –  abdu Apr 15 '13 at 13:16
    
@abdu The idea with the parskip package is just to load it; no need to set \parskip nor to explicitly call \parskip. You don't need the line \setlength{\parskip}{0pt} (you can delete it) and you don't need to use \parskip in your document. –  Gonzalo Medina Apr 15 '13 at 13:34
    
alright! I'll just use \par\bigskip. Thanks one more time for all the infos, a big help! –  abdu Apr 15 '13 at 13:39

If you don't need all the "baggage" of an additional package like titlesec, you can simply modify these aspects of your headings yourself. See this example. I use a few sections and save the original section definition, so we can see a comparison.

I then define and use a section "prelude" prior to the invocation of the original section command. Then I add a "postlude" to the sectioning command. The prelude and the postlude here both add an extra em of vertical space, but you could use it to put in other sectioning highlights like rules, etc.

\documentclass{article}
\begin{document}
\section{First Section}

This is the first line of text.  Note the vertical spacing.  

\section{Second Section}

Observe the spacing prior to and following the sectioning command. Now let me
redefine a few things.

\makeatletter
\let\origsection\section
\renewcommand\section{\@ifstar{\starsection}{\nostarsection}}

\newcommand\nostarsection[1]
{\sectionprelude\origsection{#1}\sectionpostlude}

\newcommand\starsection[1]
{\sectionprelude\origsection*{#1}\sectionpostlude}

\newcommand\sectionprelude{%
  \vspace{1em}
}

\newcommand\sectionpostlude{%
  \vspace{1em}
}
\makeatother

\section{Next Section}
Did this text drop 1em lower relative to the heading than the prior
section?  If so, we have succeeded.

\section{Final Section}

And the result is permananent, as you can see.

\end{document}

enter image description here

share|improve this answer
    
Hey thanks for your answer Steven. But I think I'll use the titlesec package just because I know how it works now. And since I'm using the report class I need chapters sections and subsections it's makes more sense to use the titlesec package. But thanks a lot, I'll save your code and try to use it in the future! =) –  abdu Apr 15 '13 at 11:01
    
@abdu. I understand completely. It's just one more option, depending on the particular need. –  Steven B. Segletes Apr 15 '13 at 11:03

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.