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.

Possible Duplicate:
Define latex command to create new type of heading

I have to create a new command that makes a new heading style. Here is a simplified version:

\newcommand{\subheading}[1] {\vspace*{1em}\normalfont {#1}}

And a minimal example:

\documentclass{scrartcl}
\usepackage{ucs} \usepackage[utf8x]{inputenc} \usepackage{lipsum}

\newcommand{\subheading}[1] {\vspace*{1em}\normalfont {#1}}

\begin{document}

\lipsum[1]
\subheading{One of these subheadings}
\lipsum[1]   

\end{document}

The problem here is that the subsequent line will be indented, as LaTeX will interpret it as a new paragraph. Obviously, however, the first line of a new section should not be indented. How can I achieve this?

Update: The subheading should also be left aligned, and itself not be indented.

share|improve this question

marked as duplicate by lockstep, Joseph Wright Sep 3 '11 at 11:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
How about a minimal working example, that shows the problem, so I can see it and try to correct? –  Tom Bombadil Sep 3 '11 at 10:17
    
Simple but rather ugly: \newcommand{\subheading}[1] {\vspace*{1em}\normalfont {#1}\par\vspace*{1ex}\noindent} and then continue the text immediately, e.g. \subheading{Guarantee}The guarantee is .... If that doesn't work then please do as Tom suggested and provide a MWE –  mas Sep 3 '11 at 10:32
    
Sorry for my stupidity, should have added a MWE in the first place. Here you go! Also, I noticed that the heading is also indented, which should not be the case. –  Ingo Sep 3 '11 at 11:05
add comment

2 Answers 2

up vote 1 down vote accepted

You are using a KOMA class. KOMA provides the command minisec. The space above of minisec is set to 1.5ex.

To set the font series you can use addkomafont or setkomafont

\documentclass{scrartcl}
\usepackage{ucs} \usepackage[utf8x]{inputenc} \usepackage{lipsum}
\begin{document}

\lipsum[1]
\minisec{One of these subheadings}
\lipsum[1]   

\end{document}

To create our own minisec you can use the internal definition as master:

\documentclass{scrartcl}
\usepackage{color}
\usepackage{ucs} \usepackage[utf8x]{inputenc} \usepackage{lipsum}
\makeatletter
\newkomafont{subheading}{}
\newcommand\subheading[1]{\@afterindentfalse \vskip 1.0ex
  {\parindent \z@
    \ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
      \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak
    \usekomafont{subheading}#1\par\nobreak}\nobreak%
  \@afterheading
}
\makeatother

\addtokomafont{subheading}{\color{red}}

\begin{document}

\lipsum[1]
\subheading{One of these subheadings}
\lipsum[1]   

\end{document}

One advantage you can use the KOMA commands setkomafont, addtokomafont and usekomafont

share|improve this answer
    
Very elegant, Marco. Thanks! –  Ingo Sep 3 '11 at 11:30
add comment

You could define a heading using LaTeX's \@startsection command, such as:

\newcounter{subheading}[subparagraph]
\renewcommand{\thesubheading}{\thesubparagraph.\arabic{subheading}}
\makeatletter
\newcommand\subheading{\@startsection{subheading}{6}{0pt}
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\normalfont\normalsize}}
\newcommand{\l@subheading}{\bprot@dottedtocline{6}{14em}{7em}}
\newcommand{\subheadingmark}[1]{}
\makeatother

The output, when added to your minimal example code, is:

subheading example

You can customize it as desired. Also a table of contents entry is prepared, if needed.

share|improve this answer
add comment

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