1

I have several paragraphs each with unique headers of differing lengths:

\documentclass[12pt]{article}

\begin{document}

\subsection{Subsection 1}

\paragraph{Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

\subsection{Subsection 2}

\paragraph{Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

\paragraph{Long Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

\end{document}

I'm looking for a global setting which will variably format each paragraph's text such as (disregarding the '...'):

Subsection 1

Title Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. ........Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

Subsection 2

Long Title Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text .................here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph .................text here.

Long Long Title Paragraph text here. Paragraph text here. Paragraph text here. Paragraph ..........................text here. Paragraph text here. Paragraph text here. Paragraph text here. ..........................Paragraph text here.

I'm sure there's a enumitem solution, however I want to stick with using paragraphs and stay away from enumitem workarounds. I believe some usage of \hangindent and/or \hangafter might work, but I'm not sure how to do so.

  • 2
    I thing what you need is a description list. – user11232 Aug 18 '14 at 0:29
  • @HarishKumar Like I said, I want to stick with using paragraphs and stay away from enumitem, or any sort of listing, workarounds. – Zach Aug 18 '14 at 0:32
  • \paragraph is the wrong markup here, that is a fourth level heading after section,subsection,subsubsection You are missing level three headings (which will show up if you increase secnumdepth or tocdepth so the section hierarchy is used in full) – David Carlisle Aug 18 '14 at 9:26
  • @DavidCarlisle I realize. I didn't include the higher levels for the sake of the min. example. – Zach Aug 18 '14 at 22:18
  • OK:-) (it was worth mentioning as \paragraph is one of the more misunderstood latex commands:-) – David Carlisle Aug 19 '14 at 9:03
2

You can define \myparagraph like this:

\usepackage{calc}  %% provides `\widthof` macro
\newlength{\mylen}
\newlength{\mylength}
\newcommand{\myparagraph}[2][]{%
\setlength{\mylen}{\widthof{\textbf{#2}}}
\setlength{\mylength}{\dimexpr\mylen+1em\relax}
\paragraph[#1]{#2}
\hangindent=\mylength
}

And then use \myparagraph{Title} whenever you want hanging.

\documentclass{article}
\usepackage{calc}
\newlength{\mylen}
\newlength{\mylength}
\newcommand{\myparagraph}[2][]{%
\setlength{\mylen}{\widthof{\textbf{#2}}}
\setlength{\mylength}{\dimexpr\mylen+1em\relax}
\paragraph[#1]{#2}
\hangindent=\mylength
}

\begin{document}

\subsection{Subsection 1}
\myparagraph{Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

\subsection{Subsection 2}
\myparagraph{Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

\myparagraph{Long Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.