3

I am listing a bunch of itens that are left-aligned (actually, I am using the \hspace command); then, for one of them, I need to do a definition by cases, so i'm using the equation mode and, inside it, the case mode. My problem is: when I do it like that this item comes centered, and I can't seem to find a way to put it left-align. Any suggestions?

EDIT: I'd like to have this implemented in a local-way; that is, generically equations would still be centered but in this particular case I'd like to be able to have them left-aligned...

MWE

\documentclass[11pt,a4paper]{book}

\usepackage[portuguese]{babel}

\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}

\usepackage{amssymb}

\usepackage{amsmath}

\usepackage{amsthm}

\usepackage{indentfirst}

\begin{document}


\hspace{1.5cm} $ x = something....$

\hspace{1.5cm} $ y = something...$

\begin{equation*}
z = 
\begin{cases}
1 & \text{if } x > 0 \\
-1 & \text{if } x \leq 0.

\end{cases}
\end{equation*}

\end{document}
5
  • 1
    Do you really have that blank line before \end{cases}?
    – egreg
    Commented May 18, 2014 at 20:21
  • I am not sure, but I don't think it's a problem!
    – essay
    Commented May 18, 2014 at 20:23
  • Could you please change the title of your question to something more specifically reflecting its topic?
    – user4686
    Commented May 18, 2014 at 22:01
  • You don't need an equation environment to use cases. Just do the z equation like the others: \hspace{1.5cm} $ z = \begin{cases}, etc. However, I would recommend some version of the itemize environment (as in the answer by Peter Grill), rather than \hspace, to get the indentation.
    – Dan
    Commented May 19, 2014 at 2:59
  • i was avoiding itemize because i don't want any numbering/ bullet point/ things like that - but i am sure there's a way to avoid this, i'll look into it.
    – essay
    Commented May 19, 2014 at 11:05

3 Answers 3

2

I would suggest you use a list environment, such as itemize with the enumitem package, along with an inner math environment such as aligned:

enter image description here

Notes:

  • The showframe packagewas used just to show the page margins. It is not needed in your actual use case.
  • You can adjust the setting of the leftmargin as desired to get the text all the way to the left.

Code:

\documentclass{book}

\usepackage{showframe}
\usepackage{amsmath}
\usepackage{indentfirst}

\usepackage{enumitem}

\begin{document}

\begin{itemize}[leftmargin=2.0cm]
\item[] $ x = something....$
\item[] $ y = something...$
\item[] $\begin{aligned}
            z = \begin{cases}
                1 & \text{if } x > 0 \\
                -1 & \text{if } x \leq 0.
            \end{cases}
        \end{aligned}$
\end{itemize}
\end{document}
1
  • this is actually rather elegant and helpful, thank you.
    – essay
    Commented May 19, 2014 at 11:06
2

flush left

\documentclass[11pt,a4paper]{book}
\usepackage[portuguese]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[fleqn]{amsmath}
\usepackage{amssymb,amsthm}

%% CODE FOR ENVIRONMENT ALLOWING SOME DISPLAYS TO BE FLUSHLEFT
%% BUT THE DEFAULT WITHOUT THE ENVIRONMENT REMAINS TO CENTER THEM
\makeatletter
\@fleqnfalse
\@mathmargin\@centering
\newenvironment{flmath}[1][0pt]
     {\@fleqntrue
      \@mathmargin#1\relax}
     {}
\makeatother

\begin{document}

\textbf{left margin = 1.5cm}

\noindent\hspace{1.5cm}$ x = something....$

\noindent\hspace{1.5cm}$ y = something...$

\begin{flmath}[1.5cm]
\begin{equation*}
z = 
\begin{cases}
1 & \text{if } x > 0 \\
-1 & \text{if } x \leq 0.
\end{cases}
\end{equation*}
\end{flmath}


\textbf{left margin = parindent}

\indent\smash{\rule[-2cm]{1pt}{2.2cm}}\kern-1pt $z$

\begin{flmath}[\parindent]
\begin{equation*}
z = 
\begin{cases}
1 & \text{if } x > 0 \\
-1 & \text{if } x \leq 0.
\end{cases}
\end{equation*}
\end{flmath}

\textbf{Normal centered equations}


\hrule

\begin{equation*}
z = 
\begin{cases}
1 & \text{if } x > 0 \\
-1 & \text{if } x \leq 0.
\end{cases}
\end{equation*}

\hrule

\end{document}
1

Here's another way, using stacks and \scalerel, the latter which scales the (width-constrained) brace to the size of what follows

\documentclass[11pt,a4paper]{book}
%\usepackage[portuguese]{babel}
%\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
%\usepackage{amssymb}
%\usepackage{amsmath}
%\usepackage{amsthm}
%\usepackage{indentfirst}
\usepackage{scalerel}
\usepackage{tabstackengine}
\def\ind{\par\noindent\hspace{1.5cm}}
\setstacktabulargap{1em}
\begin{document}
\ind$ x = something....$
\ind$ y = something...$
\ind$z = \addstackgap{\scalerel[1.7ex]{\{}{%
  \tabularCenterstack{rl}{%
    $1$ & if $x > 0$ \\
    $-1$ & if $x \protect\leq 0.$%
  }}}$
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .