Text Formattinghow to avoid section hypenation

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
dmuthu_cse
Posts: 97
Joined: Fri Sep 04, 2009 4:56 pm

how to avoid section hypenation

Post by dmuthu_cse »

Dear friends,

I have very large section title, which goes upto two lines with hypenation. I want the section title to be justified, but it should not be hypenated anyways.

Please help me.

Regards,
Muthu

Code for your reference:

Code: Select all

\documentclass[10.5pt,english]{book}
\usepackage{fancybox,array,amsmath,amssymb,babel}
\usepackage[centering,
  headheight=14pt,
  headsep=10pt,
  includehead,
  papersize={18cm,24cm},
  text={15.25cm,19.2cm},
  dvips=false,
  pdftex=false,
  vtex=false]{geometry}
\usepackage[cam,a4,center,dvips]{crop}
\headheight = 14pt
\headsep = 10pt
\hyphenpenalty=5000
% title formating %
\usepackage{titlesec}
\titleformat{\section}{\large \fontfamily{phv} \bfseries\uppercase}{\thesection}{1em}{\raggedbottom}
\titleformat{\subsection}{\fontfamily{phv}   
\fontsize{11}{27.5}\bfseries}{\thesubsection}{1em}{\raggedbottom}
\titleformat{\subsubsection}{\fontfamily{phv}   \bfseries}{\thesubsubsection}{1em}{\raggedbottom}
\titlespacing{\subsection}{0pt}{*2}{*1}
\titlespacing{\subsubsection}{0pt}{*2}{*1}

\begin{document}
\thispagestyle{empty}
\setcounter{chapter}{1}
\setcounter{secnumdepth}{3}
\setcounter{page}{1}

\section{Classification Of Indicating Instruments According To Limiting Error}
\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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to avoid section hypenation

Post by localghost »

Since you are already using the package, you should read the titlesec manual regarding package options. The 10.5pt option for the document class is useless. The log file should include an according warning.


Best regards
Thorsten
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

how to avoid section hypenation

Post by gmedina »

Hi Muthu,

supressing hyphenation might result in bad boxes in your document. I would prefer a rather cumbersome solution treating each case individually.

In your example, the line break occurs after "Lim" and before "iting", so you can use a box to store the first part of the tile: "Classification Of Indicating Instruments According To" (setting the box width to a convenient value and using the [s] modifier to force the text to stretch) and then use the box, a change line command \\ and the final part of the title in the argument of the \section command. An example:

Code: Select all

\documentclass[10.5pt,english]{book}
\usepackage{fancybox,array,amsmath,amssymb,babel}
\usepackage[centering,
  headheight=14pt,
  headsep=10pt,
  includehead,
  papersize={18cm,24cm},
  text={15.25cm,19.2cm},
  dvips=false,
  pdftex=false,
  vtex=false]{geometry}
\usepackage[cam,a4,center,dvips]{crop}
\headheight = 14pt
\headsep = 10pt
\hyphenpenalty=5000
% title formating %
\usepackage{titlesec}
\titleformat{\section}{\large \fontfamily{phv} \bfseries\uppercase}{\thesection}{1em}{\raggedbottom}
\titleformat{\subsection}{\fontfamily{phv}   
\fontsize{11}{27.5}\bfseries}{\thesubsection}{1em}{\raggedbottom}
\titleformat{\subsubsection}{\fontfamily{phv}   \bfseries}{\thesubsubsection}{1em}{\raggedbottom}
\titlespacing{\subsection}{0pt}{*2}{*1}
\titlespacing{\subsubsection}{0pt}{*2}{*1}

\begin{document}
\thispagestyle{empty}
\setcounter{chapter}{1}
\setcounter{secnumdepth}{3}
\setcounter{page}{1}

\newcommand\mybox{\protect\makebox[14.1cm][s]{\MakeUppercase{Classification Of Indicating Instruments According To}}}

\section[Classification Of Indicating Instruments According To Limiting Error]{\mybox\\ Limiting Error}

\section{Classification Of Indicating Instruments According To Limiting Error}

\end{document}
Note that you now must use the optional argument of \section to have a normal aspect of the title in the ToC and in headers.
Last edited by gmedina on Wed Mar 31, 2010 8:28 pm, edited 1 time in total.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to avoid section hypenation

Post by localghost »

Why so complicated?

Code: Select all

\usepackage[raggedright]{titlesec}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

how to avoid section hypenation

Post by gmedina »

localghost wrote:Why so complicated?

Code: Select all

\usepackage[raggedright]{titlesec}
Because your suggestion still yields hyphenated titles:

Code: Select all

\documentclass{book}
\usepackage[raggedright]{titlesec}

\titleformat{\section}{\large \fontfamily{phv} \bfseries\uppercase}{\thesection}{1em}{\raggedbottom}

\begin{document}

\section{Classification Of Indicating Instruments According To Limiting Error}

\end{document}
Am I missing something?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to avoid section hypenation

Post by localghost »

Hm, mysterious. I often used this package option and never faced a hyphenation in a heading. That's why I recommended this. It works for me after commenting the title formatting command.

Code: Select all

\documentclass[english]{book}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[raggedright]{titlesec}

%\titleformat{\section}{\large \fontfamily{phv} \bfseries\uppercase}{\thesection}{1em}{\raggedbottom}

\begin{document}

\section{Classification Of Indicating Instruments According To Limiting Error}

\end{document}
It seems that the font family setting causes the trouble because dropping it removes the misbehaviour.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Re: how to avoid section hypenation

Post by gmedina »

Yes, I can confirm that. However, now the format specified by the OP will be lost and, if I understood him correctly, he wants to suppress hyphenation but keeping the justification (which I interpreted as without flushing the text) and, of course, the modified format.

Perhaps writing a message to Javier Bezos should be considered.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to avoid section hypenation

Post by localghost »

I did some more testing and in general the sans serif font causes difficulties. The code below works neither.

Code: Select all

\documentclass[english]{book}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[raggedright]{titlesec}

\titleformat{\section}{\large\sffamily\bfseries\uppercase}{\thesection}{1em}{\raggedbottom}

\begin{document}

\section{Classification Of Indicating Instruments According To Limiting Error}

\end{document}
The sans serif font for the headings could be specified in the package options. But not a complete new font. And the formatting to uppercase would get lost, too.

So I agree regarding the note to the package maintainer. And perhaps an option for real uppercase headings would be nice (not only small caps).
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Re: how to avoid section hypenation

Post by gmedina »

I'll write a note to the maintainer about the sans serif/raggedright issue. I would also like to include your suggestion about "real" uppercase shape, but I don't quite understand it; can you please explain it to me in more detail? I'll post here any further notice on this regard.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to avoid section hypenation

Post by localghost »

gmedina wrote:[…] I would also like to include your suggestion about "real" uppercase shape, but I don't quite understand it; can you please explain it to me in more detail? […]
The package manual introduces some options to format the headings (Section 2.1 - Format, p. 2). There you find among others the option to format headings in small capitals (sc). My idea is to add an option »uc« which would format the headings entirely in real capitals, also known as uppercase. So the (here hypothetical) line

Code: Select all

\usepackage[raggedright,uc]{titlesec}
would format all headings ragged right and in capitals. I hope I could answer your question. And I assume the package maintainer may answers: »Write the section title in capitals directly«.

For the present the original problem could be solved by a small workaround.

Code: Select all

\documentclass[english]{book}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{titlesec}

\titleformat{\section}{\large\fontfamily{phv}\bfseries\raggedright\uppercase}{\thesection}{1em}{\raggedbottom}

\begin{document}

\section{Classification Of Indicating Instruments According To Limiting Error}

\end{document}
I think flushing the text to the left instead of justification keeps consistent spaces between words thus the best gray level. This improves the appearance.
Post Reply