I'm starting with LaTeX and have a basic question regarding formatting of paragraphs. I wanted to caption an equation mid text, but I couldn't find any convenient way without the equation floating away, so I decided to center a line in the next paragraph as a sort of caption. For that, I had to center the text using \centering. How can I prevent the following paragraphs from being centered and instead being "normal"?
- 223,288
- 415
5 Answers
Note that the approach of
{\centering Text}of the accepted answer will not work because there are not a blank line (=\par) before of the closing brace. The same apply to\begingroup\centering ... \endgroupNote also that the
centerenvironment add a noticeable vertical spacing before and after the caption (that could be or not what you want).For one line caption without additional space is enough a
\hfilafter the equation.If you left a blank line between a display math mode and
\hfil, be aware that the text is centered taking into account the paragraph indentation.Alternatively to
\hfilyou can use also a\makeboxwide as to the line width, since its content is centered by default. Unnecessarily complicated to obtain the same, unless you want a wide\fboxaround the caption or so.
MWE (blank lines are converted to \par to remark where they are.):
\documentclass{article}
\begin{document}
\[ a^2+b^2=c^2 \]
\hfil This is the Pythagorean Theorem.\par % works
\hfil This is the Pythagorean Theorem.\par % works if \parindent is 0pt
\begin{center}
This is the Pythagorean Theorem. % note the vertical spacing
\end{center}
{\centering This is the Pythagorean Theorem.}\par % oooooopps !
{\centering This is the Pythagorean Theorem.\par } % works
\noindent\makebox[\textwidth]{This is the Pythagorean Theorem.}\par % works too
\end{document}
Edit:
By the way, to use formula with captions I will make a new type of float or true captions without floats, MWE:
\documentclass{article}
\usepackage{amsmath,lipsum}
\usepackage{float}
\floatstyle{boxed}
\floatname{eq}{Equation}
\newfloat{eq}{H}{eqn}
\usepackage{caption}
\captionsetup[eq]{skip=20pt,position=top}
\begin{document}
\lipsum[2]
\begin{eq}
\[ a^2+b^2=c^2 \]
\caption{This is the Pythagorean Theorem.}
\end{eq}
\begin{eq}
\[\mathbf{F} = \frac{d \mathbf{p}}{dt} = \frac{d (m \mathbf{v})}{dt} = m \frac{d \mathbf{v}}{dt} = m\mathbf{a}\]
\caption{Newton's second law of motion}
\end{eq}
\lipsum*[13] Or maybe mora compact and simple fake floats:
\[ a^2+b^2=c^2 \]
\captionof{eq}{This is the Pythagorean Theorem.}
\[\mathbf{F} = \frac{d \mathbf{p}}{dt} = \frac{d (m \mathbf{v})}{dt} = m \frac{d \mathbf{v}}{dt} = m\mathbf{a}\]
\captionof{eq}{Newton's second law of motion}
\lipsum*[2]
\end{document}
Although really I prefer the classic numeration at right of formulas, without captions. ;)
If you want to center normal text, one usually uses the center environment:
\documentclass{article}
\begin{document}
\[ a^2+b^2=c^2 \]
\begin{center}
This is the Pythagorean Theorem.
\end{center}
\end{document}
If you insist on using centering, then make sure you put braces around your text, like {\centering This is the Pythagorean Theorem}.
- 165
Another possibility: use the gather environment (a multiline, centred, maths environment), and put the ‘caption’ on the second line:
\documentclass{article}
\usepackage{amsmath, amssymb}
\begin{document}
\begin{gather}
a\not\equiv 0\mod p \implies a^{p-1}\equiv 1\mod p \\
\text{\small This is known as \emph{lil’Fermat}.}\notag
\end{gather}
\end{document}
- 271,350
If you include amsmath and want to center a single line, an easy solution can be to use \text{} into an equation:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ a^2+b^2=c^2 \]
\[\text{This is the Pythagorean Theorem.}\]
$$ \text{This is the Pythagorean Theorem.} $$
\end{document}
- 111
An easy way to do this is to use the switch command for the alignment you want. Here is an example of centering the text over a multicol environment and returning to justified text for the following content. There may be a better way, but I got errors trying to use a centering environment or a \par. The \justify command can also be placed just before \Blindtext.
\documentclass{report}
\usepackage{multicol}
\usepackage{ragged2e}
\usepackage{blindtext}
\begin{document}
\begin{multicols}{3}
[\centering Some over text\\justify
\rule{\textwidth}{0.4pt}
]
\Blindtext
\end{multicols}
\noindent\rule{\textwidth}{0.4pt}
\end{document}
- 1




\centeringin a group (ie, sourround it in a brace group{\centering ...}, or use\begingroup\centering...\endgroup). But, it would really be helpful if you composed a fully compilable MWE including\documentclassand the appropriate packages that sets up the problem so that we can test that the suggestion actualy works for you and perhas suggest an alternate way to achive your desired intent (such as using thecaptionpackage). – Peter Grill Sep 05 '18 at 23:40\begingroup\centering ... \endgroup, which was using\begin{center} ... \end{center}and it did exactly what I wanted. Thank you very much! – Álvaro Sep 05 '18 at 23:52