# How to use \newline in a macro?

I want to introduce \newline after the figure label instead of :. I am aware that caption package does this via \captionsetup. However, I would like to do it without it.

I read from the memoir class manual (page no - 214) about the trick of declaring an extra argument for \fnum@figure and not using it, which gobbles the undesired colon from \@makecaption. Now, for memoir class I can introduce \newline instead of : as the label separator. It works.

Original caption:

Modified in Memoir class:

This trick also works for scrreprt. However, for scrreprt, : disappears but \newline is not introduced. I have also tried \\, \\* and \vspace{\baselineskip}. None of them work.

Modified caption without ":" but no \newline

Introducing \newline at the start of the \caption also doesn't work.

I think that I am making some rookie mistake here. I have read that most macros do not distinguish between spaces and \newlines. Is this the reason why this won't work?

Please let me know a workaround.

%\documentclass{memoir}
\documentclass{scrreprt}

%Memoir manual page no - 214
%Note the extra unused argument.
\makeatletter
\renewcommand{\fnum@figure}[1]{\textsc{\figurename~\thefigure} \newline \sffamily}
\makeatother
%
\begin{document}
\begin{figure}
\centering
\rule{3cm}{2cm}
\caption{A Caption}
%\caption{\newline A Caption}
\end{figure}
\end{document}

-
Many caption styles put the caption into \mbox so the width can be measured and like all LR boxes or table l entries they are then one-line. In any case you should not be putting explict line breaks into the caption argument but rather controlling the caption style if that is what you want. As you say caption package does this for the standard classes, but memoir and scrrprt probably have their own caption style setup commands which should be used (not really familiar with either) –  David Carlisle Jan 10 '13 at 17:18
@DavidCarlisle caption package works with Memoir and scrreprt as well. I am just trying to do this on my own to learn. –  devendra Jan 10 '13 at 17:21
well it is easy to define a simple \@makecaption with a two line layout but harder to fit in with all the other features those classes may add like automatic caption positioning, continuation captions etc, so it depends a bit what you want to learn. will post an example... –  David Carlisle Jan 10 '13 at 17:33
@DavidCarlisle I copied the macro definitions of \@makecaption from report/scrreprt classes, then redefined it with \newline instead of :. It doesn't work. But if : is replaced by --, it does. –  devendra Jan 10 '13 at 17:38
yes that's expected try \mbox{a\newline b} –  David Carlisle Jan 10 '13 at 17:39

As an example this is a simple caption handler that makes a two line layout (if your captions may be long you could change ll to lp{5cm} or whatever you need for multi-line version) it does not respect all the options the class may have controlling caption positioning.

\documentclass{scrreprt}

%Memoir manual page no - 214
%Note the extra unused argument.
\makeatletter
\renewcommand{\fnum@figure}[1]{\textsc{\figurename~\thefigure}}
\def\@@makecaption#1#2#3{%
{\centering\begin{tabular}{@{}ll@{}}
\csname fnum@\@captype\endcsname&{}\tabularnewline
&#3\end{tabular}\par}
}
\makeatother
%
\begin{document}
\begin{figure}
\centering
\rule{3cm}{2cm}
\caption{A Caption}
%\caption{\newline A Caption}
\end{figure}
\end{document}

-
I guess the key idea is to use tabular environment instead of adding a \newline. –  devendra Jan 10 '13 at 17:49
You need to typeset the caption in a construct that allows multiple lines so a tabular or (more usually) a parbox or somesuch, if you'd used a parbox here though you would have to work a bit harder to get the indentation style but using a tabular it is easy as the alignment is automatic –  David Carlisle Jan 10 '13 at 17:56
From report.cls, \@makecaption definition has a line \sbox\@tempboxa{#1: #2}. Could I add \tabular environment in the box to achieve the same result as your example? –  devendra Jan 10 '13 at 17:59
report.cls first does that and if the box is small uses it otherwise resets as a multi-line parbox, but in your example the text is small and fits on a line so it will be used, but yes you could use the same definition as above (but with one @ and just two arguments not three in report) –  David Carlisle Jan 10 '13 at 18:02
Thanks a lot for letting me pick your brain. –  devendra Jan 10 '13 at 18:03