Problem when using multiple multirow commands in a table - latex

I am trying to create a three columns table with a format
like this.
Naturally, the description is longer than the name column. Additionally, I want to use \multicolumn command for the example column for aesthetics reason. Here is the code,
\begin{document}
\begin{table}
\begin{tabular}{|c|p {5 cm}|p {5 cm}|}
\hline
\multirow{2}{*}{Complex Type} & \multirow{2}{5 cm}{\parbox[c]{5 cm}{This variable type is used to declare a complex number, the real part and also the imaginary part.}} & \multicolumn{1}{l|}{Defining a complex number 3.0 + 5.0 i :} \\
& & \multicolumn{1}{l|}{complex :: a = (3.0, 5.0)} \\
\hline
\multirow{4}{*}{Character Type} & \multirow{4}{4 cm}{This variable type is used to store one character by default. It can be used to store string or multiple characters using the len modifier. The len modifier works exactly the same as kind modifier. The example is on how to declare two variables, var1 for a character and var 2 for a sentence holder.} & character :: var1 \\
& & character (len = 40) :: var2 \\
& & var1 = "A" \\
& & var2 = "How do you turn this on?" \\
\hline
\end{tabular}
\end{tabular}
I apologize if the code is too long. It seems the problem is because the entire row cell's height is not adjusted for the highest cell. It is fixed based on the first column instead. I have tried to try several method and nothing works. Any suggestions?

It looks like you are trying to use these complicate constructs with \multicolumn and \multirow just to change the alignment and add line breaks, this can be done much more easily:
\documentclass{article}
\usepackage{geometry}
\usepackage{multirow}
\usepackage{array}
\begin{document}
\begin{table}
\begin{tabular}{|c|m{5cm}|>{\raggedright\arraybackslash}m{6.2cm}|}
\hline
Complex Type &
This variable type is used to declare a complex number, the real part and also the imaginary part. &
Defining a complex number 3.0 + 5.0 i : \linebreak
complex :: a = (3.0, 5.0) \\
\hline
Character Type &
This variable type is used to store one character by default. It can be used to store string or multiple characters using the len modifier. The len modifier works exactly the same as kind modifier. The example is on how to declare two variables, var1 for a character and var 2 for a sentence holder. &
character :: var1 \linebreak
character (len = 40) :: var2 \linebreak
var1 = "A" \linebreak
var2 = "How do you turn this on?" \\
\hline
\end{tabular}
\end{table}
\end{document}

Related

Typesetting the numbered mathematical formula in latex

How to typeset the following numbered mathematical formula:
Use amsmath's cases environment:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\Delta(x) = \begin{cases}
1 & \text{if $x > 0$} \\
-1 & \text{if $x < 0$} \\
0 & \text{otherwise}
\end{cases}
\]
\end{document}
Here is one way to do it:
$
\Delta(x)=
\left\{
\begin{matrix}
1 & \mathrm{if}~x>0 \\
-1 & \mathrm{if}~x<0 \\
0 & \mathrm{otherwise}
\end{matrix}
\right.
$
Which produces the equation you wanted like this:
The example LaTeX equation
This type of equation has a few key tricks in it:
The left bracket has to be declared as \{ in order for LaTeX to
know to display it since it is a special character
Also, the left brace has to be resized to match however many rows you include in your equation, which is done by the \left command preceding it. This can also be done for (, [, etc.
Since you have a \left command, it has to be accompanied by a \right}, but you don't want to display the right brace, so the \right. ends the section without displaying the right brace.
The \mathrm command turns the text inside it back to normal text (removing the math mode temporarily) so that your "if" and "otherwise" aren't italicized.
The ~ just adds a little space so that your "if" doesn't collide with the x > 0, which often happens when using mathrm
Alternatively, you can check out this post for other ways to write piecewise functions in LaTeX. I hope this helps.

Using MathJax I need a solution for \ensuremath

I'm using a MathJax in several projects and it generally works like a charm.
Today, however, I ran into a problem during the translation of a part of an existing LaTeX document with the following align-environment:
\begin{align}
& (\lambda x.(\lambda y.(\lambda z.xyz)))abc \\
= & \text{\{ impliciete toepassing expliciet maken \}} \\
& (((\lambda x.(\lambda y.(\lambda z.xyz)))a)b)c \\
= & \text{\{ \ensuremath{\beta}-reductie, substitutie van \ensuremath{x}door \ensuremath{a}\}} \\
& ((\lambda y.(\lambda z.ayz))b)c \\
= & \{\text{\ensuremath{\beta}-reductie, \ensuremath{y\,:=b}}\} \\
& (\lambda z.abz)c \\
= & \text{\{ \ensuremath{\beta}-reductie, \ensuremath{z\,:=c}} \\
& abc \\ \boxed{} \end{align}
The result rendered with LaTeX is this (sorry for the Dutch text ;-):
The align-environment is essentially a math context, so if you want text, you need to enclose that text with \text{...}. But when you need again math symbols within that text, you escape the text context by enclosing the maths with \ensuremath{...}.
And MathJax renders it like:
That Mathjax centers everything doesn't matter, that is something I can handle with CSS. But the rendering of \ensuremath is a problem. Clearly MathJax doesn't support \ensuremath, but I can't think of a workable workaround where I can use math symbols in a text-context.
Ideally I'ld like to have a solution using an alternative LaTeX construction (hence the cross listing)
Any ideas?
You should use $...$ or \(...\) in place of \ensuremath{...}. This seems more natural to me even in LaTeX itself (as \ensuremath is really designed for use within macros that might be used inside both text- and math-modes).
So you can do
\begin{align}
& (\lambda x.(\lambda y.(\lambda z.xyz)))abc \\
= & \{\text{ impliciete toepassing expliciet maken }\} \\
& (((\lambda x.(\lambda y.(\lambda z.xyz)))a)b)c \\
= & \{\text{ $\beta$-reductie, substitutie van $x$door $a$ }\} \\
& ((\lambda y.(\lambda z.ayz))b)c \\
= & \{\text{ $\beta$-reductie, $y:=b$ }\} \\
& (\lambda z.abz)c \\
= & \{\text{ $\beta$-reductie, $z:=c$ }\} \\
& abc \\ \boxed{} \end{align}
I also put the \{ and \} outside the \text{}, though you can do them inside if you prefer.
The centering is probably due to CSS on your page, as MathJax left-justifies these by default.

LaTeX align environment missing $ inserted

I'm using an Align environment inside of a proof, and I'm getting the error "Missing $ inserted." I've commenting out all but the first line of the align makes the error go away, but I still can't figure out what the problem is. No solution I could find works. Am I missing something?
\documentclass[12pt,letterpaper]{article}
\usepackage{ifpdf, enumerate}
\usepackage{mla}
\usepackage{gb4e}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{stmaryrd}
\newcommand{\tuple}[1]{\ensuremath{\left \langle #1 \right \rangle }}
\newcommand{\evaluation}[2][]{\ensuremath{\llbracket #2\rrbracket^{#1}}}
\begin{document}
\begin{proof}
\begin{align*}
\evaluation[\mathbb{M}]{(Mx)(D (x) \& V (x))} = 1 \iff \\
\evaluation[\mathbb{M}]{\lbrack \alpha / x \rbrack (D (x) \& V (x))} = 1 \text{for most constants \alpha} \\
\evaluation[\mathbb{M}]{(D (\alpha) \& V (\alpha))} = 1 \text{for most constants \alpha } \\
\evaluation[\mathbb{M}]{D (\alpha)} = 1 \text{and} \evaluation[\mathbb{M}]{V (\alpha)} = 1 \text{for most constants \alpha } \\
F(\alpha) \in F(D) \text{and} F(\alpha) \in F(V) \text{for most constants \alpha } \\
\intertext{Examining the definitions of the model, we see that there are only four entities that are both in $F(D)$ and $F(V)$: Alice, Bob, Colin, and David. Because this is not more than half of the total twelve entities in the universe, our naive definition of ``most'' is not satisfied. Therefore the statement is false, which implies that the truth value of the origenal proposition is not 1.}
\end{align*}
\end{proof}
\end{document}
Here is what the error message looks like.
./test.tex:24: Missing $ inserted.
<inserted text>
$
l.24 \end{align*}
?
You've missed only one tricky fact: \alpha only works in math mode, so if you replace all occurrences of
\text{for most constants \alpha} \\
(lines 18, 19, 20, 21) with
\text{for most constants }\alpha \\
then your tex will compile sweetly. Also:
\text{for most constants}\ \alpha \\
or:
\text{for most constants $\alpha$} \\
as you already did in line 22 of your code (...$F(D)$ and $F(V)$...).
This answer is not applicable to this exact case, but the given error can also pop up if the "amsmath" package is not being used. It becomes tricky because the whole code looks alright except I had forgotten to add the \usepackage{amsmath} line in the beginning of the document.

Iteration in LaTeX

I would like to use some iteration control flow to simplify the following LaTeX code.
\begin{sidewaystable}
\caption{A glance of images}
\centering
\begin{tabular}{| c ||c| c| c |c| c|| c |c| c|c|c| }
\hline
\backslashbox{Theme}{Class} &\multicolumn{5}{|c|}{Class 0} & \multicolumn{5}{|c|}{Class 1} \\
\hline
\hline
1 &
\includegraphics[scale=2]{../../results/1/0_1.eps}
&\includegraphics[scale=2]{../../results/1/0_2.eps}
&\includegraphics[scale=2]{../../results/1/0_3.eps}
&\includegraphics[scale=2]{../../results/1/0_4.eps}
&\includegraphics[scale=2]{../../results/1/0_5.eps}
&\includegraphics[scale=2]{../../results/1/1_1.eps}
&\includegraphics[scale=2]{../../results/1/1_2.eps}
&\includegraphics[scale=2]{../../results/1/1_3.eps}
&\includegraphics[scale=2]{../../results/1/1_4.eps}
&\includegraphics[scale=2]{../../results/1/1_5.eps} \\
\hline
... % similarly for 2, 3, ..., 22
\hline
23 &
\includegraphics[scale=2]{../../results/23/0_1.eps}
&\includegraphics[scale=2]{../../results/23/0_2.eps}
&\includegraphics[scale=2]{../../results/23/0_3.eps}
&\includegraphics[scale=2]{../../results/23/0_4.eps}
&\includegraphics[scale=2]{../../results/23/0_5.eps}
&\includegraphics[scale=2]{../../results/23/1_1.eps}
&\includegraphics[scale=2]{../../results/23/1_2.eps}
&\includegraphics[scale=2]{../../results/23/1_3.eps}
&\includegraphics[scale=2]{../../results/23/1_4.eps}
&\includegraphics[scale=2]{../../results/23/1_5.eps} \\
\hline
\end{tabular}
\end{sidewaystable}
I learn that the forloop package provides the for loop. But I am not sure how to apply it to my case? Or other methods not by forloop?
If I also want to simply another similar case, where the only difference is that the directory does not run from 1, 2, to 23, but in some arbitrary order such as 3, 2, 6, 9,..., or even a list of strings such as dira, dirc, dird, dirb,.... How do I make the LaTeX code into loops then?
You may use pgffor package, a tool provided by pgf. The basic syntax is:
\foreach \n in {0,...,22}{do something}
Notably, this for loop is not restricted to integers, for example:
\foreach \n in {apples,burgers,cake}{Let's eat \n.\par}
Something like this will take care of the body of your tabular:
\newcounter{themenumber}
\newcounter{classnumber}
\newcounter{imagenumber}
\forloop{themenumber}{1}{\value{themenumber} < 24}{
% \hline <-- Error here
\arabic{themenumber}
\forloop{classnumber}{0}{\value{classnumber} < 2}{
\forloop{imagenumber}{1}{\value{imagenumber} < 6}{
& \includegraphics[scale=2]{
../../results/\arabic{themenumber}/\arabic{classnumber}_\arabic{imagenumber}.eps
}
}
}
\\
\hline
}
I had to comment out the first \hline because it gave me an error:
You can't use `\hrule' here except with leaders.
I'm not sure what that means; if you really cannot live without the double line, I can look into it more.
Also note that you have to use <; for example, <= 24 will not work.
As to your update: I would simply declare a command that takes the argument that you're looping over. Something like this:
\newcommand\fordir[1]{do something complex involving directory named #1}
\fordir{dira}
\fordir{dirb}
\fordir{dirc}
\dots

Collapsible minibox environment in LaTeX

I'm trying to learn LaTeX, currently because otherwise, my professors will be nearly unable to read my homework assignments. I've come across something I want to do, but don't seem to be able to, ie. I have searched google (possibly with a poor keyword set) and not found a solution.
The specific case is as follows: I want to put an ams flalign environment inside a box and have multiple such environments side by side. I have achieved this using minipage, but minipage asks for a width. I would like to use the smallest width in which the flalign environment fits. I realize that I can set the width to 0pt, but I can't help wondering if there's something that is intended to do this.
Also, should I be using minipage? Is there another command I don't know?
Thanks for your reply.
EDIT:
An attempted clarification as to what I want to do. I want equations which are standard, known, given, etc. and short on the left. To the right of those, I want relevant derived equations (and maybe their derivations. Further right, I want actual calculations plugged in.
I feel like what I want is a tabular environment with 3 columns, but I don't think I can put an equation environment in a tabular environment.
This looks like what I want when I render it.
\begin{minipage}[t]{0pt}
\begin{flalign*}
\sigma & = F / A&\\
A & = \pi \left(d/2\right)^2&\\
\epsilon &= \frac{\sigma}{E}&\\
\epsilon_{trans} &= - \nu \epsilon_{longi}& \\
\epsilon &= \frac{\Delta l}{l}&\\
l &= \left( \epsilon + 1 \right) \times l_0&
\end{flalign*}
\end{minipage}
\hspace*{0pt}
\begin{minipage}[t]{0pt}
\begin{flalign*}
d & = \unit[1.8]{mm} = \unit[1.8\e{-3}]{m} &\\
F_T & = \unit[1300]{N}&\\
E_{\text{stainless steel}}&=\unit[193\e9]{Pa}&\\
l_0 & = \unit[.2530]{m}&\\
\nu & = .33&\\
\sigma &= \frac{\unit[1300]{N}}{\pi \times \unit[3.24\e{-6}]{m^2}}&&= \boxed{\unit[127.7\e6]{Pa}}\\
&&&=\boxed{\unit[18,524]{psi}}\\
\epsilon &= \frac{\unit[127.7\e6]{Pa}}{\unit[193\e9]{Pa}} &&= \boxed{6.6\e{-2}}\\
\epsilon_{trans} &= -.33 \times 6.6\e{-2} &&=\boxed{-2.2\e{-2}}\\
l &= \left( 6.6\e{-2} + 1 \right) \times \unit[.2530]{m} &&= \boxed{\unit[.2797]{m}}
\end{flalign*}
\end{minipage}
I'm not sure exactly what you're trying to achieve, but amsmath's align* environment might do what you want (without resorting to minipages):
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x&=y & X&=Y & a&=b+c & mn&=ab\\
x’&=y’ & X’&=Y’ & a’&=b & m'n'&=a'b'\\
x+x’&=y+y’ & X+X’&=Y+Y’ & a’b&=c’b & m'&=a'
\end{align*}
\end{document}
As to your minipage question: it requires a width because TeX needs to know where to break the lines. If you don't want the line-breaking algorithm to be used, you probably don't want a minipage.
Edit:
If you want multiple columns and don't care about the vertical alignment of material across the columns, that can be obtained easily enough with the multicols package:
\documentclass{article}
\usepackage{multicols}
\usepackage{lipsum}% just for some example text
\begin{document}
% The * version allows the columns to have ragged bottoms.
% The argument 2 is the number of columns.
\begin{multicols*}{2}
\lipsum[1]% one paragraph of Lorem ipsum.. filler text
\vfil% fills the remainder of the column with white space
\columnbreak% force a column break
\lipsum[2]% another paragraph of text
\vfil% fills the remainder of the column with white space
\end{multicols*}
\end{document}
You might find something to help you in the empheq and mathtools packages. empheq allows you to box equations and mathtools should provide some useful environments for stacking them horizontally.

Resources