0

Good evening,

I'd like to ask the following problem that i was unable to solve.

Computing a math text i obtained the following error just because i omitted a point after \end{center}.

this:

\begin{center}

$f(g_{1}) = f(g_{2})$,

\end{center} \\

doesn't compute.

This does:

\begin{center}

$f(g_{1}) = f(g_{2})$, 

\end{center}. \\

I'd like to know how to fix it becaus it is quite ugly to see a nosense point in my Notes,

thank you all, any help would be appreciated

moewe
  • 175,683
  • 3
    What's the purpose of \\ after \end{center} to begin with? Do you know about \[...\], which is actually what you want? – egreg Jul 15 '18 at 21:22
  • I was going to ask the same thing as @egreg; and, why the period? – GuM Jul 15 '18 at 21:24
  • No @egreg could you explain better ? – jacopoburelli Jul 15 '18 at 21:25
  • 2
    I suppose the error you're getting is that there is no line to end. You are misusing \\ It can only be used at the end of a line with content, you can't use it at the start of a line. After the \end{center} you're at the start of a line, so you can't have \\ next. You need something in the line. Anything. It will work with . it will work with a, it will work with elementary, my dear Watson but it won't work nothing. – Au101 Jul 15 '18 at 21:25
  • @GuM i put the period because i noticed that with it computed but not without it – jacopoburelli Jul 15 '18 at 21:26
  • 1
    But \\ is for use in tables and things, it's rarely the right thing to be used in the text, @egreg is saying you should have text text text \[ f(g_{1}) = f(g_{2}), \] text text text. He is right – Au101 Jul 15 '18 at 21:27
  • @Au101 so should i remove \ ? – jacopoburelli Jul 15 '18 at 21:27
  • It worked, thanks! (I'm sorry for this inconvenient) – jacopoburelli Jul 15 '18 at 21:32
  • 1
    @jacopoburelli no no! Never apologise! You did nothing wrong, you did the right thing by asking. It's never too early to stop someone from misusing \\, you could have built up a really bad habit. Now you know =) – Au101 Jul 15 '18 at 21:34
  • 1
    Not to contradict what @Au101 says, but you would had done an even better thing if you had sistematically studied an introductory guide to LaTeX. Trying to learn it by asking one thing at a time makes for a very painful learning… – GuM Jul 15 '18 at 21:40
  • So when i should \ ? Just understand it clearly @Au101 – jacopoburelli Jul 15 '18 at 21:40
  • @jacopoburelli You should use it in tabulars, arrays, matrix environments and the like, where you need to end rows. You can also use it in the verse environment, which is for poetry, where you want to break lines without ending paragraphs. Only use it to break a line in the middle if you have some positive reason for doing so. Never use it to end a paragraph, produce unjustified text, or something like that and steer clear of it is a quick way of adding a bit of vertical space – Au101 Jul 15 '18 at 21:49

1 Answers1

2

The test document

\documentclass[a4paper]{article}

\begin{document}

Some text to fill a couple of lines before some displayed 
equation that is centered on a line by itself
\begin{center}
$f(g_{1})=f(g_{2})$
\end{center} \\
and some text following the display.

\end{document}

stops with the error

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.10 a
      nd some text following the display.

that should be self-explaining: there is no line to end after \end{center}. If you go past the error by hitting return, the document is produced:

enter image description here

The same would be obtained by omitting \\.

On the other hand, this is not the preferred method for displaying equations:

\documentclass[a4paper]{article}
\usepackage{amsmath}

\begin{document}

Some text to fill a couple of lines before some displayed
equation that is centered on a line by itself
\begin{equation*}
f(g_{1})=f(g_{2}) 
\end{equation*} 
and some text following the display.

\end{document}

enter image description here

Instead of \begin{equation*}...\end{equation*} you can use \[...\] (but the former is more convenient if you later decide to number your equation and just removing * is sufficient).

There are some subtle differences in the output, but the main one is that no page break can happen before the display. Remember not to leave a blank line before the display itself.

And remember that \\ is not the method of choice to end paragraphs, for which a blank line should be used.

Please, make sure to read an introductory guide to LaTeX: see Where do I start LaTeX programming?

egreg
  • 1,121,712