4

I am trying to use the titlesec package to redefine some of my sections and subsections commands. I want the \subsection to have the text following it become wrapped but if it has a title define in it like \subsection{definitions} then it should have the title follow like normal with the title wrapping in with the text also. I can't figure out how to do it.

Below is a example tex file of my problem.

\documentclass[10pt]{article}

\usepackage{titlesec}

\titleformat{\section}[hang]{\large}{\thesection.0}{0.5em}{}[]
\titlespacing{\section}{0pc}{1pc}{1pc}

\titleformat{\subsection}[drop]{\large}{\thesubsection}{0.0em}{}[]
\titlespacing{\subsection}{5pc}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\begin{document}

\section{Purpose and Discussion}
\subsection{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dapibus est mauris, varius malesuada velit consectetur quis. Phasellus bibendum iaculis maximus. Sed at ante sed dolor tempor viverra et eu lectus. Aliquam gravida nulla non nisi dapibus, quis dapibus magna fringilla. Vestibulum non gravida magna. Sed rutrum commodo odio sagittis condimentum. 

\subsection{definitions}    

\end{document}

I am attempting to get it to look something like this. enter image description here

Thank you for any help you are able to give.

3
  • Are you open to alternatives? The \subsection title seems very list-like.
    – Werner
    Commented Dec 4, 2014 at 19:14
  • The title of your question is a little indefinite... :) Maybe you can try to be more concrete so that future users with the same or a similar problem may benefit from your question.
    – Ruben
    Commented Dec 4, 2014 at 20:13
  • And maybe have a look at tex.stackexchange.com/questions/167748/…. The problem is quite the same. The difference consists only in the actual design of the format.
    – Ruben
    Commented Dec 4, 2014 at 20:15

2 Answers 2

6

Something like this?

enter image description here

I've redefined \subsection so to have a \hangindent:

\let\oldsubsection\subsection
\renewcommand\subsection[2][]{%
\oldsubsection[#1]{#2}%
\hangindent=2.7em%
}

and used runin as shape option for \titleformat:

\titleformat{\subsection}[runin]{\large}{\thesubsection}{0.5em}{}[]
\titlespacing{\subsection}{0.5em}{1em}{0.6em}

Complete code:

\documentclass[10pt]{article}

\usepackage{titlesec}

\titleformat{\section}[hang]{\large}{\thesection.0}{0.5em}{}[]
\titlespacing{\section}{0em}{1em}{0.6em}

\titleformat{\subsection}[runin]{\large}{\thesubsection}{0.5em}{}[]
\titlespacing{\subsection}{0.5em}{1em}{0.6em}

\let\oldsubsection\subsection
\renewcommand\subsection[2][]{%
\oldsubsection[#1]{#2}
\hangindent=2.7em
}

\begin{document}

\section{Purpose and Discussion}
\subsection{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dapibus est mauris, varius malesuada velit consectetur quis. Phasellus bibendum iaculis maximus. Sed at ante sed dolor tempor viverra et eu lectus. Aliquam gravida nulla non nisi dapibus, quis dapibus magna fringilla. Vestibulum non gravida magna. Sed rutrum commodo odio sagittis condimentum.

\subsection{definitions}

\end{document} 
0
0

Does using the wrap style do what you want?

\documentclass[10pt]{article}

\usepackage[explicit, calcwidth]{titlesec}

\titleformat{\section}[hang]{\large}{\thesection.0}{0.5em}{#1}[]
\titlespacing{\section}{0pc}{1pc}{1pc}

\titleformat{\subsection}[wrap]{\filright\large}{\thesubsection~}{0.em}{#1}[]
\titlespacing{\subsection}{5pc}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\begin{document}

\section{Purpose and Discussion}
\subsection{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dapibus est mauris, varius malesuada velit consectetur quis. Phasellus bibendum iaculis maximus. Sed at ante sed dolor tempor viverra et eu lectus. Aliquam gravida nulla non nisi dapibus, quis dapibus magna fringilla. Vestibulum non gravida magna. Sed rutrum commodo odio sagittis condimentum.

\subsection{\mbox{definitions} and so}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dapibus est mauris, varius malesuada velit consectetur quis. Phasellus bibendum iaculis maximus. Sed at ante sed dolor tempor viverra et eu lectus. Aliquam gravida nulla non nisi dapibus, quis dapibus magna fringilla. Vestibulum non gravida magna. Sed rutrum commodo odio sagittis condimentum.

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .