latex: indents in the equation (boxes instead of digit) - latex

I want to do the task - addition to the column with unknown digits.
How to make everything so that it is aligned in the center of the boxes and digits?
To digits were under the digits, boxes under the digits, digits under the boxes?
\def\msquare{\mathord{\scalerel*{\Box}{gX}}}
\begin{multline*}
\begin{array}{r}
+
\begin{array}{r}
\msquare64\msquare\msquare\msquare\\
661977\\
\end{array}\\
\hline
\begin{array}{r}
1\msquare\msquare631\msquare
\end{array}\\
\end{array}
\end{multline*}

This can be done with an array. As your values are just squares or number, it is better to use the tabular environment where intercolumn spacing can be more finely controlled. To do that, the simpler is to redefine the tabcolsep length, but there packages like array that can provide other means to control it.
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
% \def\msquare{\mathord{\scalerel*{\Box}{gX}}} % redifined, because I do know what \Box does.
\def\msquare{\raisebox{1mm}{\framebox[2mm][r]{}}}
\setlength{\tabcolsep}{0.5pt}
\begin{multline*}
\begin{array}{r}
+
\begin{tabular}{ccccccc}
&\msquare&6&4&\msquare&\msquare&\msquare\\
&6&6&1&9&7&7\\
\hline
1&\msquare&\msquare&6&3&1&\msquare
\end{tabular}\\
\end{array}
\end{multline*}
\end{document}
To avoid the redefinition of tabcolsep in all your document, enclose this code in braces.

Related

How to define the actual column width in two-column Latex document (excluding the space between the columns)?

I would like to redefine \columnwidth and set it to the value corresponding to (\textwidth-\columnsep)/2.
This is because I would like to use this redefined command inside tabular environment for controlling column width.
The problem with \columnwidth is that it disregards the space between columns, therefore it doesn't do the job.
Here's what I'm talking about. The following code compiles but gives an undesirable output.
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\setlength{\columnsep}{2cm}
\newcommand\testcolwidth{(\textwidth-\columnsep)/2}
\begin{document}
\lipsum
\begin{table}[!h]
\begin{tabular}{p{.25\columnwidth}|p{.75\columnwidth}}
\hline
col 1 & col 2
\end{tabular}
\end{table}
\lipsum
\end{document}
This is what the output look like. It's undesirable because I don't want this line (and the table) to stretch into the space between the columns.
I have tried to define column width with the following line:
\newcommand\testcolwidth{(\textwidth-\columnsep)/2}
It results in an error when using \testcolwidth in place of \columnwidth. The error reads: Illegal unit of measure (pt inserted)
Any help? Thanks a lot.
The columnwidth already takes into account the space between the columns of the article, what is missing in your code is the tabcolsep which defines the space between the table columns. In your example, this space gets added four times, once at the front, once at the end and once on each site of the |. If you want to manually define your table like this, you need to know in advance how many columns it will have:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\setlength{\columnsep}{2cm}
\newcommand\testcolwidth{\dimexpr\columnwidth-4\tabcolsep}
\begin{document}
\lipsum
\begin{table}[!h]
\begin{tabular}{p{.25\testcolwidth}|p{.75\testcolwidth}}
\hline
col 1 & col 2
\end{tabular}
\end{table}
\lipsum
\end{document}
Much easier to let a package like tabularray do the job for you:
\documentclass[twocolumn]{article}
\usepackage{tabularray}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{table}[!h]
\begin{tblr}{
colspec={X[1]|X[3]}
}
\hline
col 1 & col 2
\end{tblr}
\end{table}
\lipsum[2]
\end{document}

align enviroment tab and kerning

I have been using common align environment from amsmath and noticed strange behaviour of kerning when placing the & sign from either side of the + sign. Namely assume the following code and the result it produces for me:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a&+b\\
a+&b
\end{align}
\end{document}
Is this a bug? If this is intended behaviour, can you please explain why the kerning is different in those cases?
For all it could matter I am using TexStudio 4.0.1 and MikTex (Console version 4.8, all packages updated on 24th Aug 22) to produce the output from the code.
I think it's working as expected. The ampersand characters defines a boundary between left and right columns, which in turn are right and left aligned, respectively. Everything to the left is pushed leftwards and everything to the right is pushed rightwards.
Consider the code
\documentclass{article}
\usepackage{amsmath}
\setlength\fboxsep{0pt}
\begin{document}
\begin{align}
\boxed{a} \clap{\rule[-3pt]{0.4pt}{12pt}}& + b\\
a + \clap{\rule[-3pt]{0.4pt}{12pt}}& \boxed{b}
\end{align}
\end{document}
IMO there's the perfect split between two columns. The extra spacing comes from + being an operator so LaTeX does add extra spacing around it.
In your code, there is another issue. An ampersand placed at the right of an operator cancels its status of being the operator. The effect is it's losing expected spacing; the same would happen with =. Adding anything between an operator and & restore its status. Therefore, {} placed right before & is he easiest solution
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a & + b \\
a + {}& b
\end{align}
\end{document}

How to align an enumerated list in latex?

Suppose I want to center align the enumerated list. I did this:
\begin{center}
\begin{enumerate}[label=(\Roman*)]
\item Equation 1
\item Equation 2
\item Equation 3
\item Equation 4
\end{enumerate}
\end{center}
This is not working nicely. I have also tried without 'enumerate' and just 'center' and labeling manually. It does work but the alignment is not looking perfect.
Also instead for center we can also do:
I. Equation 1 \quad II. Equation 2
III. Equation 3 \quad IV.Equation 4
You cannot center an item list like that. Enumerate is a formatting environment that will supersedes the center environment.
What can be done is to put the enumerate list in a box (like a minipage), and to center this box.
Standard minipage requires a width, but there is a package (varwidth) that allows to define minipages with an unknown width (more precisely, you give a width parameter, but if width is smaller than that, the actual with is used).
So here is a solution with varwidth.
\documentclass{article}
\usepackage{enumitem}
\usepackage{varwidth}
\usepackage{tasks}
\begin{document}
\begin{center}
\begin{varwidth}{\textwidth}
\begin{enumerate}[label=(\Roman*)]
\item Equation 1
\item Equation 2
\item Equation 3
\item Equation 4
\end{enumerate}
\end{varwidth}
\end{center}
\end{document}
If you want to have several enumerate items per line, your solution is not very robust, as you must adjust the spacing depending on the item length if you want your items to be aligned.
The 'tabto' package provides a way to do the alignment in a flexible way. But the best solution is to use the 'tasks' package that allows to define columned list. This package is not as smart as others to determine the item width and, if required, this must be given explicitely. The parenthesized parameter is the number of columns. As previously, if you want to center globally the environment, you must use varwidth.
\begin{center}
\begin{varwidth}{\textwidth}
\begin{tasks}[label={(\Roman*)},label-width={1cm}](2)
\task Equation 1
\task Equation 2
\task Equation 3
\task Equation 4
\end{tasks}
\end{varwidth}
\end{center}
For simple lists like yours, a tabular could also be used.
You can just use
\begin{enumerate}[label=(\Roman*)]\centering

How to insert latex dot without new line

Im trying to add a dot like • for a dot product but it always ends up acting like a bullet point creating a new line. I've tried \cdot and \bullet. I think its being treated as a bullet because I'm doing it inside an itemized list. Is there a way to make it just as a dot?
Have you tried :
$\bullet$
Try \cdot in math mode. It is a good way to indicate multiplication:
\documentclass{article}
\begin{document}
Here is a product: $a \cdot b$.
\end{document}
Note that the dollar symbol represents the math mode.
just had the same problem...
Math mode $...$ is not essential for this:
\documentclass{minimal}
\begin{document}
\noindent
Here's an example with $\bullet$ math mode
\newline
And here one in \textbullet text only
\newline
Although you may want to give the last \textbullet \ more spacing
\end{document}
giving:

Latex Multiline Equations

Is it possible to get multline like behavior within a gather
environment? I have a set of equations in a gather environment, but
one of them is too long, and I'd like to split it up onto two lines
where the first line is left-aligned and the second line is right-aligned
(just like multline). If there is a way of aligning individual lines
within the gather or split environment (like flushleft or flushright but
functional in mathmode) this would solve the problem.
The mathtools package has an inner multlined environment similar to gathered and the likes, but it required a small amount of manual tweaking:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
% \begin{multline}
% \framebox[0.65\linewidth]{\strut} \\
% \framebox[0.6\linewidth]{\strut} \\
% \framebox[0.65\linewidth]{\strut} \\
% \framebox[0.6\linewidth]{\strut}
% \end{multline}
\begin{gather}
\framebox[0.8\linewidth]{\strut} \\
\begin{multlined}[b][\linewidth-3\multlinegap]
\framebox[0.65\linewidth]{\strut} \\
\framebox[0.6\linewidth]{\strut} \\
\framebox[0.65\linewidth]{\strut} \\
\framebox[0.6\linewidth]{\strut}
\end{multlined} \\
\framebox[0.4\linewidth]{\strut}
\end{gather}
\end{document}
I haven't tested this, but you can try putting \hfill in front of the second line.
Having said that: IMHO, multline behavior inside a gather environment is undesirable. Especially if you have the fleqn option enabled, you should consider the following option:
put the long equation inside a split, with alignment on the left side of the equality. Assuming the right hand side is too long, put its second part on a new line (still inside the split) and use \hspace{1cm} (or some other length) to indent the second part a bit further.
For an overview of all AMS multiline blocks, see the amsmath documentation.

Resources