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 want my section titles to be same as the margins of the text. Here is an example of the problem (see title in section 1.1). I want a similar behavior as title (1.2). Any suggestions? What am I missing here?

\documentclass{report}
\usepackage{blindtext}

\begin{document}

\chapter{Hope}

\section{Hope of the Essential Trigonometry TRIGTEST}
\blindtext

\section{Hope of the Essential Trigonometry TRIGOTEST}
\blindtext

\end{document}

enter image description here

share|improve this question
    
    
@cmhughes The "TRIGTEST" in title 1.1 is out of bounds. I want Latex to either divide the word as in title 1.2, or move the word to the second line. –  HBat Aug 11 at 20:38
    
It doesn't know how to hyphenate the word. You need to tell it where the word can be broken. –  cfr Aug 11 at 20:40
    
@cfr I see but isn't the behavior in the title 1.1 aberrant? If it doesn't know how to hyphenate it should move it to the next line, instead of exceeding the boundaries of margin? –  HBat Aug 11 at 20:45
1  
No. In some cases, TeX ends up letting a line run over because it cannot figure out a better point to break the line. The algorithm TeX is using is not as simple as the one that a word processor uses, for example, where it just moves to the next line if stuff doesn't fit. If you run in draft mode, you will see these places where TeX is 'stuck' as black boxes at the margins where things run over the edge. –  cfr Aug 11 at 20:48

2 Answers 2

up vote 3 down vote accepted

The titlesec package is used for this. With the option of raggedright, you can get what you mean. See this code,

\documentclass{report}
\usepackage{blindtext}
\usepackage[raggedright]{titlesec}

\begin{document}
\chapter{Hope}

\section{Hope of the Essential Trigonometry TRIGTEST}
\blindtext

\section{Hope of the Essential Trigonometry TRIGOTEST}
\blindtext

\end{document}

with the desired output in both subsections:

enter image description here

share|improve this answer
    
Great, this is exactly what I was looking for. Thanks. –  HBat Aug 11 at 21:14

TeX does not know how to hyphenate the word 'trigtest' so you will need to tell it how to do so in the preamble:

\documentclass{report}
\usepackage{blindtext}
\hyphenation{trig-test}
\begin{document}

\chapter{Hope}

\section{Hope of the Essential Trigonometry TRIGTEST}
\blindtext

\section{Hope of the Essential Trigonometry TRIGOTEST}
\blindtext

\end{document}

Hyphenated headings

share|improve this answer
    
What if I don't want it to hyphenate? How can I force it to move any word to the next line (if it doesn't know the hyphenation) and obey the margin rules strictly? –  HBat Aug 11 at 20:49
1  
@HBat Well you said you wanted similar behaviour to the behaviour for section 1.2 which is hyphenated. You could force a line break in a particular case, of course. You almost certainly do not want TeX to 'obey the margin rules strictly' but you could adjust the penalties which determine how 'bad' TeX considers various different outcomes. (For example, tell it that too much white space is less bad to encourage line breaks with under-full lines.) However, this is likely to create more problems unless the context is quite specialised. –  cfr Aug 11 at 20:53
    
@HBat See tex.stackexchange.com/questions/51263/…. –  cfr Aug 11 at 21:00
    
Good to know these. Thanks for the answer. I will go with \linebreak but good to know about \hyphenation{trig-test}. –  HBat Aug 11 at 21: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.