2

My company has a Word document with lots of styles based on the basic headings. I need to create LaTeX equivalents and am struggling with how to do so because I need to do more than just redefine \chapter, \section, etc.

As a simple example, there are three styles based on (Word's) Heading 2 style. All three have some common properties: they are Arial 13pt bold, with 10 pts vertical space before, keep with next paragraph properties (so that line can't be the last line on a page), and a level 2 table of contents entry.

From there, the styles diverge: there's a style that uses a blue color for the font, a second style that autonumbers (so it counts Activity 1, Activity 2, etc), and a third that has no numbering or color changes.

What is the best way to create these styles? Ideally I'd like to create commands so I can say \activity or whatever for any of the three.

  • Sounds like your company has developed some specialized templates for headers. Must the output created by the templates be preserved exactly? – Mico Jun 10 '15 at 19:21
  • I'm confused. Does this mean that there are three separate types of level 2 heading styles? Are there separate types of all levels of heading? How many levels of headings are there? – dgoodmaniii Jun 10 '15 at 19:22
  • @dgoodmaniii There are three different types of headings, all of which show up at level 2 within Word's table of contents. – Colin Jun 10 '15 at 19:24
  • Are they all number together, or do they maintain separate numbering schemes? – dgoodmaniii Jun 10 '15 at 19:25
  • @Mico there is some flexibility but not much. For more context, I've been given the authority to attempt to implement the existing templates in LaTeX so we can do better version control of the documents than with Microsoft Word files. But, my solution needs to be passably similar to our existing documents. – Colin Jun 10 '15 at 19:27
3

Here's something that (probably) does what you want. It doesn't use Arial, because I don't have it and don't like it, but substitutes Latin Modern Sans. You type \newsection with two arguments; the first says which type of \newsection it is, and the second is the section name. a is one type (no number, blue), b is another (no number, still black, no font change), and anything else will make the third (numbered, sans serif). Each prints itself as a section-level heading in the TOC. (I assume that section is your second-level heading; if that's not true [say, if you're using the article class], you would need to change section to subsection in the \addcontentsline directives.

\documentclass{book}
\usepackage{etoolbox}
\usepackage{lmodern}
\usepackage{xcolor}
\newcounter{newsect}
\setcounter{newsect}{0}
\makeatletter%
\def\newsection#1#2{%
    \ifstrequal{#1}{a}{%
        \fontsize{13pt}{15pt}\selectfont%
        \hbox to\linewidth{\textcolor{blue}{\textsf{#2}}\hfil}%
        \addcontentsline{toc}{section}{#2}%
    }{\ifstrequal{#1}{b}{%
        \fontsize{13pt}{15pt}\selectfont%
        \hbox to\linewidth{#2\hfil}%
        \addcontentsline{toc}{section}{#2}%
    }{%
        \stepcounter{newsect}%
        \fontsize{13pt}{15pt}\selectfont%
        \hbox to\linewidth{%
            \hbox to2em{\thenewsect\hfil}\textsf{#2}%
            \hfil%
        }%
        \addcontentsline{toc}{section}{%
          \hbox to2em{\thenewsect\hfil}#2}%
    }}%
    \penalty10000%
}%
\makeatother%
\begin{document}

\tableofcontents

\newsection{a}{Lorem}
\newsection{b}{Ipsum}
\newsection{c}{Loquitur}
\newsection{c}{whatever}
\newsection{b}{does}
\newsection{a}{this}
\newsection{c}{work?}
\end{document}

Will give you this:

Weird Section Headings

A couple of caveats here: section titles will look bad if more than one line (fixable, but I'm putting this together on the fly here). The color and font changes do not carry into the TOC here, but that's also easily fixed. I believe that \penalty10000 will prevent any page breaks in the space following one of these headings, as requested, no matter how terrible it might look; \parskip will probably expand to an unacceptable degree in the close cases to make up for one of these headings skipping to the next page. Ideally, it would simply leave empty space at the bottom of the page when this happens; this board has ways to do that, but I don't have time to look them up right now.

Finally, this looks terrible, and I pity you having to reproduce it. Maybe a little experience with LaTeX will lead your employers to some better style choices.

  • When I tried to reproduce this, it doesn't seem to restore the font back to normal for the following paragraph, and the leading/trailing vertical space is missing. But this is close! – Colin Jun 11 '15 at 20:17
2

The code below gives us the following output:

colinNewSectioncommands

% arara: xelatex
\documentclass{scrreprt}
\usepackage{blindtext}
\usepackage{fontspec}
\usepackage{xcolor}
\DeclareSectionCommand[beforeskip=-10pt,afterskip=10pt,
    font={\color{blue!40!black}\fontspec{Arial}\normalfont},
    style=section,
    level=1,
    tocindent=2em,
    tocnumwidth=2em,
    indent=0pt
]{activityB}% B, as in blue
\DeclareSectionCommand[beforeskip=-10pt,afterskip=10pt,
    font={\fontspec{Arial}\normalfont},
%   counterwithin=chapter,
    style=section,
    level=1,
    tocindent=1em,
    tocnumwidth=2em,
    indent=0pt
]{activity}
\renewcommand{\blindtext}{This is just a simple test}
\begin{document}
\tableofcontents
\chapter{pogo penguin}
\blindtext
\section{walzing Wombat}
\blindtext
\activity{samba snake}
\blindtext
\activity*{salsa squirrel}
\blindtext
\activityB{Lambada leguan}
\blindtext
\end{document}

The example needs to be run with XeLaTeX, to easily use Arial. It uses pretty new features of KOMA-script, so an up to date version is required.

It might be a better idea though, to define new floating environments and have the activities in a list of their own. But without knowing the actual use case, it is hard to know.

  • Can you expand on the "floating environments" idea? – philosophyguy Jun 10 '15 at 20:34
  • @philosophyguy If the activities are rather short sections (third or half of a page), afloating box might be a better idea, and an extra list with just the different activies using the caption command (or a different command, but a similar mechanism). It really depends on the use case. – Johannes_B Jun 10 '15 at 20:47

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.