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 some custom \section formatting with a horizontal rule, and I'm trying to DRY out my code by using titlesec to define default formatting options. But I can't exactly reproduce what happens when not using titlesec. Here's an example:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}

\begin{document}

% Plain xrfill:
\section*{\large\normalfont First Section \xrfill[0.6ex]{0.4pt}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

% Via titlesec:
\titleformat{\section}[runin]{\large}{\thetitle}{1em}{#1 \xrfill[0.6ex]{0.4pt}}
\section*{Second Section (\texttt{titlesec})}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

% Titlesec with a \\ at the end:
\titleformat{\section}[runin]{\large}{\thetitle}{1em}{#1 \xrfill[0.6ex]{0.4pt}\\}
\section*{Third Section (line break)}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

\end{document}

Note that using titlesec doesn't put the following text in a new paragraph. I tried to solve this with \\ but that doesn't work either. What can I do to make this work the same way as it would without titlesec?

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

Use the [display] style instead of the [runin] style:

\titleformat{\section}[display]{\large}{\thetitle}{1em}{#1\space\xrfill[0.6ex]{0.4pt}}
\section*{Second Section (\texttt{titlesec})}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.

enter image description here

share|improve this answer
    
Great, thanks! But the titlesec documentation seems to claim that runin mimics the default behavior. So why wouldn't this work with runin? –  jtbandes Dec 25 '12 at 5:54
1  
The [runin] style is equivalent to the standard classes' \paragraph style. The default style (which in your example would also work) is [hang], which is like the standard \section command (see p.3 of the docs). Because of the rule, I think that the [display] is more appropriate, though. –  Alan Munn Dec 25 '12 at 6:04
add comment

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.