11

Any package documentation that looks like this:

\titleformat{<command>}[<shape>]{<format>}{<label>}{<sec>}{<before-code>}[<after-code>]

is considerably less helpful for the newbie (like me) than examples. It does not give the newbie reader much of a clue as to what exactly ought to be typed into a real document. Do I type in those angle braces? Curly braces? Square braces? What, precisely, goes inside any or all of these delimiters?

Examples are the way to document.

The titlesec documention does have examples at the end, but they are too few, and do not cover the case I'm interested in.

My question is this: what is a simple, straight-forward way to format section titles? There are several design requirements for my output:

  1. The section number should not be indented at all.
  2. The entire body of the section text should be indented similarly to what the enumerate package does, except that I would prefer normal prose paragraph indenting instead of newlines. That is, the first lines of paragraphs in the section are indented "twice", while the subsequent lines are only indented "once". Here "once" and "twice" mean relative to the section number.

I'm sure there's a way to do this, but my searching here and elsewhere has failed to uncover it. I'd be grateful for any assistance. Thanks in advance!

Here is a minimal almost-working example using the enumerate package. I could almost do it with this package, except for wanting bold section titles and so forth.

\documentclass[12pt]{article}
\usepackage{enumerate}

\begin{document}

\begin{enumerate}[I.]
\item Section Title

This level has a great spacing from the 1. on the left to the first word ``This''. And then, if I want 
a hierarchy, the heading there, an `A.' in this case,
\begin{enumerate}[A.]
\item Subsection Title

is nicely lined up with the indented text above. However, I would like to change
this indenting to use normal prose paragraph indenting, such as
\end{enumerate}
\end{enumerate}

Normal paragraph prose indenting, where the first line is indented, and the rest of the paragraph is not. 
However, the non-indented text needs to be at the indentation of the ``This'' above, and the first lines need
to be indented one more slot, of the same width.

\end{document}

And here's a minimal working example I typed in in MS Word (naturally, I had to man-handle the indenting to be what I wanted):

Minimal Working Example in MS Word

  • 4
    You noticed titlesec has an appendix with examples, right? – Johannes_B Aug 09 '16 at 16:17
  • 2
    YOu noticed we have a titlesec tag here. Many questions, almost all have a fully working example. – Johannes_B Aug 09 '16 at 16:18
  • 2
    You want a different interface? Don't use a standard class, switch to KOMA. You can do \RedeclareSectionCommand[indent=0em,font=\Large,level=0]{chapter} if you feel the need. – Johannes_B Aug 09 '16 at 16:19
  • 3
    If you hate titlesec that much, you can pay someone to do the job for you. No joke, they have read the manual and understood it. They are experts. – Johannes_B Aug 09 '16 at 16:21
  • 3
    Completely unrelated and off-topic? Have you ever had a look at the tabu documentation? Or the lengthy TikZ manual? Or a nice ConTeXt reference? – Johannes_B Aug 09 '16 at 16:23
  • 6
    Ranting about software provided to you for free by people who were not paid for their effort is surely not a very practical way to get help. And speaking of examples, I don't see you having provided one so that people could perhaps help you with your problem. – Alan Munn Aug 09 '16 at 16:26
  • 4
    Please understand that almost everything related to LaTeX including packages, was made by voulanteers, and did it just to be kind to others. Please do not piss over somebodys attempt at making the life of others easier, especially when the attempt in question is one of the most used packages out there. If you feel that the documentation needs improvements, there are other ways to say this. The examples are in the documentation, along with information about using them, allthough they it might be better for them to be located along with the \titleformat-macro. – Runar Aug 09 '16 at 16:31
  • 1
    No, I don't hate titlesec, I'm just not a fan of its documentation. The examples in the back are too few, don't include what I want to do, and don't help me generalize the package usage so I can figure out what I want to do. – Adrian Keister Aug 09 '16 at 16:31
  • 1
    It appears that the titlesec package is for experts. While I've done a fair bit of typesetting in LaTeX, I would not consider myself an expert. So you could say that part of my question is this: what is a non-expert way to do this? – Adrian Keister Aug 09 '16 at 16:32
  • 2
    Did you really expect anything under section 3. Advanced interface to be as easy as pie? – Runar Aug 09 '16 at 16:34
  • @AdrianKeister, does my document help? It gives many commands that you input into each section. I am no expert, but it did not seem too over my head. – auden Aug 09 '16 at 16:34
  • 2
    @AdrianKeister Latex is done by people who commit their time for free. If you don't like something about it, be constructive. Don't spend your energy with ranting about it. If you don't like the documentation, why not help to improve it? – samcarter_is_at_topanswers.xyz Aug 09 '16 at 16:36
  • 1
    From http://tex.stackexchange.com/help/dont-ask: "avoid asking subjective questions where … your question is just a rant in disguise: “______ sucks, am I right?”" – samcarter_is_at_topanswers.xyz Aug 09 '16 at 16:42
  • 2
    I have edited the question to be less abrasive, as the community here did not appreciate it. I have strong feelings about how to document software, as this is my profession. I appreciate that LaTeX is maintained by volunteers, but I do not regard that fact as an excuse for what I regard as a less helpful way to document software. I'm interested in moving on from titlesec, if that's not going to work, and finding a solution. – Adrian Keister Aug 09 '16 at 16:43
  • 4
    I appreciate the edit, but now add a Minimal Working Example showing what you tried with titlesec and how it doesn't do what you want. See I've just been asked to write a minimal example, what is that?. As @Johannes_B notes, the titlesec tag on the site has lots of fully worked examples to choose from. – Alan Munn Aug 09 '16 at 16:56
  • 1
    @Alan, I would provide a minimal working example if I could, but I'm not even that far. I can give an example of the desired destination, but from the enumerate package viewpoint. – Adrian Keister Aug 09 '16 at 16:57
  • 1
    @AdrianKeister You could at least do all the footwork, like providing the documentclass, the required packages and so on. – samcarter_is_at_topanswers.xyz Aug 09 '16 at 17:06
  • I've got a minimal, almost-working example in the original question now. – Adrian Keister Aug 09 '16 at 17:09
  • after seeing you edit to the post, I see that my answer is not what you are looking for. But I still don't understand exactly what you want. Maybe you could add an illustration? Even a handdrawn-image is great. Never underestimate pen and paper. – Runar Aug 09 '16 at 17:19
  • @Runar, here's an exact example in MS Word of what I'm interested in. – Adrian Keister Aug 09 '16 at 17:29
  • 4
    I think this question can easily be re-written without the initial documentation rant. Just ask what you want, period. – Werner Aug 09 '16 at 18:38
  • 1
    Book design is a complex discipline. They are literally infinite possibilities. I'm willing to improve the manual, of course, but please, have in mind I cannot provide solutions for everything and I haven't got a crystal ball (in other words, I cannot answer on beforehand "do not cover the case I'm interested in" for every user and for every book). I'm happy the package is useful for many people, even if there is still room for improvements. – Javier Bezos Aug 10 '16 at 09:00

2 Answers2

11

I am a bit unsure of how exactly you want these indentations to be, So I've created one where the section title would be at the same indentation-point across. The code is based on the example of a section given in the documentation section 9.1 A full example:

\titleformat{\section}
   {\normalfont\Large\bfseries}{\thesection}{1em}{}

To get the same indentation-point, we need to calculate the width of the section-number, as these vary in width, depending on which number is being printed. (8 is wider than 1 in most fonts, and a 100 is ofcourse wider). This can be done with the command \widthof{content} from the calc-package. Then we set the length for the intendation to two \parindents, which is the length of a normal indent, minus the width of the section number.

But as the \parindent is not the same everywhere, and is zero within the \titleformat-macro, we need to calculate it outside of that. Therefore a new length is created, \anIndent, which captures that length.

To get the indentation you want, I grabbed the answer by Werner posted in Indent an entire paragraph / section?. This works across pages, and is easier to use that a minipage. It would ofcourse be great if there was some solution which worked without setting these macroes manually for every section.

Also, do you really want indentation of the first line? I don't think that is a very common way to do it. Normally, the first paragraph is not indented, only subsequent ones.

EDIT: I've now made a new environment, to make the syntax a bit better. It is based upon the adjustwidth-environment from the changepage-package. The new environment is called indentedSection and takes one argument, the number of indentations. 1 for section 2 for subsection and 3 for subsubsection. I also added support for subsubsection

Output

enter image description here

Code

\documentclass[11pt]{article}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{indentfirst}
\usepackage{calc}
\usepackage{changepage}

\newlength{\anIndent}
\setlength{\anIndent}{\parindent}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{2\anIndent-\widthof{\thesection}}{}

\titleformat{\subsection}
  {\normalfont\large\bfseries}{\thesubsection}{3\anIndent-\widthof{\thesubsection}}{}

\titleformat{\subsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsection}{4\anIndent-\widthof{\thesubsubsection}}{}

\newenvironment{indentedSection}[1]{%
    %Input #1: Level of indentation
    \begin{adjustwidth}{#1\anIndent+\anIndent}{}
        \hspace{\anIndent}% Indent first line
        \ignorespaces% Ignor any space at start of environment
    }{\end{adjustwidth}}

\begin{document}
\section{Baz}
\begin{indentedSection}{1}
    \lipsum[2]
\end{indentedSection}
\subsection{Foo}
\begin{indentedSection}{2}
    \lipsum[2]
\end{indentedSection}
\subsubsection{hello}
\begin{indentedSection}{3}
    \lipsum[2]
\end{indentedSection}
\end{document}
Runar
  • 6,082
  • after seeing you edit to the post, I see that this is not what you are looking for. – Runar Aug 09 '16 at 17:17
  • If you could get the Lorem ipsum text to line up with the B in Baz, except for the first line, which is indented yet again, like it is down at "Nam dui" near the bottom, that'd be exactly what I'm looking for. – Adrian Keister Aug 09 '16 at 17:20
  • I made an edit, just to show something of what you are looking for. I am really not sure how to do it without minipages, which you of course do not want. I'll look into it, and see if I can help you. – Runar Aug 09 '16 at 17:33
  • I notice that the Baz section doesn't have new paragraph indenting like the Foo section does. Can the Baz section indent, say, the second paragraph the same way as the Foo section? – Adrian Keister Aug 09 '16 at 17:41
  • I think I've got it: \hfill \begin{minipage}{\textwidth-2\anIndent} \hspace{\anIndent} \lipsum[1] \hspace{\anIndent} \lipsum[2] \end{minipage} – Adrian Keister Aug 09 '16 at 17:51
  • 2
    subsections are now working. I think this answer could be approved, to give a much better syntax, so you don't need to write \begin{adjustwidth}{3\anIndent}{} \hspace{\anIndent} \end{adjustwidth} every time. Dont use minipage for this, that was just a bad idea on my part. use the new code with adjustwidth. As explained in my answer, minipage doesn't work when the content is bigger than remaining space of the page. – Runar Aug 09 '16 at 17:51
  • I created a \myPar command to simplify the adjustwidth environment calls. – Adrian Keister Aug 09 '16 at 18:21
1

Okay, here is a 27 page document explaining titlesec. (If that link doesn't work, try this one.) I'm reading it myself, now that I found it. It has your abominations, but it explains the abominations. That makes it all okay, right? There's also this website that also has an online LaTeX editor; it includes working examples you can open. I'm working on fixing the first link.

Example (direct quote): <command> is the sectioning command to be redefined, i. e., \part, \chapter, \section, \subsection, \subsubsection, \paragraph or \subparagraph.

Hope this helps! I'll keep looking for other resources.

Other Resources

Oh, and in light of Johannes_B's comment, here is the TikZ manual. Very lengthy, and extremely helpful (I just started learning TikZ/LaTeX and that manual is awesome. As well as the wikibook for LaTeX.) Here and here are two more LaTeX resources that are very handy. Here is documentation for Tabu. Finally, here is a TeX stack exchange question about documentation/resources for ConTeXt.

Note: This was posted before the OP updated his question to make it clear that he wanted a problem to be solved; not documentation.

auden
  • 1,458
  • http://tug.ctan.org/tex-archive/macros/latex/contrib/titlesec/titlesec.pdf – Adrian Keister Aug 09 '16 at 16:44
  • @AdrianKeister Feel free to update/enhance the part on collab. writing. https://en.wikibooks.org/wiki/LaTeX/Collaborative_Writing_of_LaTeX_Documents (Personally, i consider this non-LaTeX specific and hence off topic. – Johannes_B Aug 09 '16 at 16:56
  • @heather: Yes, well, my obtuseness knows few bounds. ;-) That kind of documentation is not very helpful for me. And, as remarked above, the examples at the end are not varied enough for me. There's almost nothing there about indentation. – Adrian Keister Aug 09 '16 at 17:11