4

I am a beginner in LaTex and I have written the following code:

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[english, french, greek]{babel}

\begin{document}
\selectlanguage{english}

\title{Physics assignment}
\author{me}
\date{\today}
\maketitle

\section*{Excercise 1}
\selectlanguage{greek}
$m = 5kg$

$t = 0sec$: $\vec{υ} = 2m/s$

$t' = 2sec$: $\vec{υ} = 12m/s$

$\mu = 0,2$

$\vec{g} = 10m/s^2$

\end{document}

This is the output of the code. How can I make it so that the first line of the section, "m = 5kg" aligns with the rest of the lines?

Any help is greatly appreciated.

1
  • 4
    You are making new paragraphs, paragraphs are indented by default. You should probably put this into a math construction like align. Also: look up the siunitx package for formatting units, you're doing it wrong here (there are actually rules as to how unites should be formatted and siunitx makes this super easy)
    – daleif
    Mar 20 '20 at 16:27
7

Hi @PuperHacker and welcome to TeX-SE.

As you are a beginner let's go step by step.


Standards

There are many standards around the world. LaTeX's standard depends of the class and normally they are related to common standards in USA. I'm from Brazil and the common standard here (the one taught in elementary schools) is all paragraphs are indented.

So, first basic command \usepackage{indentfirst}

This is a MWE (Minimum Working Example). OBS: \usepackage{lipsum} generates dummy text.

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage{indentfirst} %(un)comment this line to test
\usepackage{lipsum}
\begin{document}
    \section{title}
    \lipsum[1]

    \lipsum[2]
\end{document}

With \usepackage{indentfirst}

enter image description here

Without \usepackage{indentfirst}

enter image description here


Equations and Units

There are many methods to input math into LaTeX.

I must be honest here, I learned about siunitx only after I started my own set of units commands, so there might be some better methods to use the package siunitx.

For more info, please check: CTAN - siunitx.

A not so minimal WE follows

\documentclass{article}
\usepackage{amsmath}
\usepackage{indentfirst}
\usepackage{siunitx}
\begin{document}
    \section{title}
    Text $m = 5 kg$ does not result in the same as $m = 5$ kg.

    With a blank line (not recommended)

    \begin{equation}
    m = 5 kg
    \end{equation}

    Without a blank line (recommended)
    \begin{equation}
    m = 5 kg
    \end{equation}

    Let's test some text commands in math mode.

    Using align
    \begin{align}
    m & = 5 kg                \\
    m & = 5 \operatorname{kg} \\
    m & = 5 \text{kg}         \\
    m & = 5 \textrm{kg}       \\
    m & = 5 \mathrm{kg}
    \end{align}

    Using split
    \begin{equation}
    \begin{split}
    m & = 5 kg                \\
    m & = 5 \operatorname{kg} \\
    m & = 5 \text{kg}         \\
    m & = 5 \textrm{kg}       \\
    m & = 5 \mathrm{kg}
    \end{split}
    \end{equation}

    Align and split don't interfere with spacing, but they label equations differently.

    \clearpage
    And now some siunitx commands and spacing
    \begin{align}
    m & = 5 \si{\kilogram}        \\
    m & = 5 \ \si{\kilogram}      \\
    m & = 5 \, \si{\kilogram}     \\
    m & = 5 \; \si{\kilogram}     \\
    m & = 5 \quad \si{\kilogram}  \\
    m & = 5 \qquad \si{\kilogram}
    \end{align} 

    And now some siunitx commands to better spacing comparing the ones without it.
    \begin{align}
    m       & = 5\si{\kilogram}            \\
    m       & = \SI{5}{\kilogram}          \\
    \vec{u} & = 12 \si{m/s}                \\
    \vec{u} & = \SI{12}{m/s}               \\
    \vec{u} & = \SI{12}{m \per s}          \\
    \vec{u} & = \SI{12}{\metre\per\second}
    \end{align}

\end{document}

and the results are

enter image description here

enter image description here

In my point of view, siunitx has the most options and is a well maintained package. If you do not want to use it, the second best approach would be \operatorname{} due the better handling of spacing.

10

With align* and siunitx:

enter image description here

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[english, french, greek]{babel}
\usepackage{amsmath}
\usepackage{siunitx}
\begin{document}
\selectlanguage{english}

\section*{Excercise 1}
\selectlanguage{greek}

\begin{align*}
m &= \SI{5}{\kg}\\
t &= \SI{0}{\s}: \vec{υ} = \SI{2}{\m\per\s}\\
t' &= \SI{2}{\s}: \vec{υ} = \SI{12}{\m\per\s} \\
\mu &= 0,2\\
\vec{g} &= \SI{10}{\m\per\s\squared}
\end{align*}
\end{document}
3

Generally, you will want to align to the = sign, as was shown by leandris. Occasionally, however, you may wish to align to both the left side of the variables AND the = sign.

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[english, french, greek]{babel}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{tabstackengine}
\TABstackMath
\begin{document}
\selectlanguage{english}

\section*{Exercise 1}
\selectlanguage{greek}
\[
\TABbinary
\setstackaligngap{0pt}
\setstackgap{L}{1.2\baselineskip}
\alignCenterstack{
&m&=& \SI{5}{\kg}\\
&t&=& \SI{0}{\s}: \vec{υ} = \SI{2}{\m\per\s}\\
&t'&=& \SI{2}{\s}: \vec{υ} = \SI{12}{\m\per\s} \\
&\mu&=& 0,2\\
&\vec{g}&=& \SI{10}{\m\per\s\squared}
}
\]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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