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.

I am new to Latex and found out how to use it a bit. Newlines are created by \\

I get the following error: \\ can only appear in a matrix or array

How do you create newlines between matrix or arrays?

Thanks

EDIT: Here's the code. This is for an online forum that processes LaTeX.

a = 
\left[
\begin {array}{ccc}
1& 2&3\\
\noalign{\medskip}
4&5&6
\end {array}
\right]

b = a .+ 1 

b = 
\left[
\begin {array}{ccc}
2&3&4\\
\noalign{\medskip}
5&6&7
\end {array}
\right]

By the way, what is the proper etiquette to post the code? Do I need code tags? Or LaTeX tags? Thanks.

share|improve this question
1  
Would you please show an example of what you are trying to achieve? –  egreg Oct 29 '11 at 15:03
1  
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in @Alan's edit. You can also highlight the code and click the "code" button (with "{}" on it). –  Werner Oct 29 '11 at 15:26
    
You can format code by selecting the text and clicking on the {} icon. It's also helpful to post complete minimal working examples (MWE). –  Alan Munn Oct 29 '11 at 15:27
    
I didn't know if I should also show it as formatted in LaTeX. How would you do that? I checked the FAQ but I didn't see anything about it. –  B Seven Oct 29 '11 at 15:41
add comment

2 Answers

up vote 4 down vote accepted

Load the amsmath package (\usepackage{amsmath}); then

\begin{align*}
a &= 
\begin{bmatrix}
1& 2&3\\
4&5&6
\end{bmatrix}
\\
b &= a \mathbin{.+} 1 
\\
b &= 
\begin{bmatrix}
2&3&4\\
5&6&7
\end{bmatrix}
\end{align*}

will print the three formulas in different lines.

The code \noalign{\medskip} works, but it's more practical to write

\\[\medskipamount]

instead of

\\
\noalign{\medskip}
share|improve this answer
add comment

Without knowing the full details of the forum that you're posting on, it's hard to be 100% sure.

However, it appears that you have not told the forum to process your code in Math Mode.

There are a variety of ways that you can enter Math Mode, including

  • $...$
  • \[ ... \]
  • \( ... \)
  • \begin{equation*}...\end{equation*}

but the forum you mention may not support all of these. Presumably it will support at least the first two.

A good approach might be to compile your code locally before posting to the forum to make sure that you know what you want it look like- this will help you to narrow down if it's the forum that is not processing your code correctly, or if you have incorrect code. A MWE example follows of what your code might look like in a document.

\documentclass{article}

\begin{document}

\[
\begin{array}{ll}
    a & = \left[
            \begin {array}{ccc}
            1& 2&3\\
            \noalign{\medskip}
            4&5&6
            \end {array}
        \right]\\
            \noalign{\medskip}
    b & = a .+ 1 \\
            \noalign{\medskip}
     & = 
        \left[
            \begin {array}{ccc}
            2&3&4\\
            \noalign{\medskip}
            5&6&7
            \end {array}
        \right]
\end{array}
\]

\end{document}
share|improve this answer
    
Sorry, I omitted the $$ or <math> tags. –  B Seven Oct 29 '11 at 16:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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