Some LaTeX formatting commands like \textcolor{red}{...}
, \sout{...}
or \textsf{...}
work fine when the thing inside is a single paragraph but fail to compile if you put a paragraph break in the argument.
\textsf{This paragraph is in sans-serif.} % OK
\textsf{This one too.
So should this one be.} % Doesn't compile.
Question 1: why is this? I feel I haven't understood how LaTeX processes these commands internally. Is there a general way to build a command that works with paragraphs or to turn one that doesn't into one that does?
Question 2: what commands, if any, can I use to apply the following changes to a block containing several paragraphs within my text? For color I know I can use the color
environment already.
- sans-serif
\textsf
or monospace\texttt
- strikeout and underline
\sout
and\ul
(fromulem
)
Best Answer
Certain commands do not permit new paragraphs:
\textbf
,\textsf
,\texttt
, etc. To achieve the effect you want, you'll need to use a different form:\bfseries
,\sffamily
,\ttfamily
,\itshape
. If you load thexcolor
package, then you can issue\color{<name_of_color>}
.If you don't want to effect document wide changes, then you need to embed these commands within some kind of grouping. That can be as simple as
{...}
or an environment like\begin{minipage}{<width>}...\end{minipage}
.Here's a MWE:
If you don't want to hassle with embedding things inside another environment or parentheses, then you can use
\normalfont
to restore settings. This won't, however, work for restoring color; for that you'll have to issue\normalcolor
or\color{black}
.In a similar fashion, you can change font sizes by issuing
\large
or\scriptsize
etc., to undo the effect of these commands (if not embedded in some kind of a group) use\normalsize
.In summary
Each font changing command is paired with a command which can work across multiple paragraphs.
These are all well documented; so it shouldn't be hard for you to find all such paired commands. However, a word of caution, do not use
\bf
,\it
, and the such. These are TeX commands and most likely will not do what you want. The LaTeX commands\bfseries
,\itshape
, only change the aspect of the text you want (series type, shape, family). Among more subtle effects the LaTeX commands enact and depending on whether the fonts you use provide support, the effects of the LaTeX commands are additive.If the commands in the second column are not embedded within some kind of a group and you want to restore default behavior, then you can issue
You can change the size of the font with the commands
The default size can be restored using
Color attributes can be changed, provided you've loaded
xcolor
. As with\textxx{...}
type commands, there is also a pair:Colors can be restored by issuing