Rearranged chapters
This commit is contained in:
parent
642861a711
commit
e28bac94c2
453
lbol.tex
453
lbol.tex
@ -549,232 +549,6 @@ Your widely spaced text goes here.
|
||||
\section{Indents}
|
||||
|
||||
|
||||
\chapter{Tables}
|
||||
|
||||
Tables in \LaTeX{} are often confusing to beginners, because there are two environments that are not quite what they seem. The \texttt{tabular} environment is used to create a table, while the \texttt{table} environment is a float that surrounds the table and can contain a caption.
|
||||
|
||||
\section{Built-in Table Environments}
|
||||
|
||||
For example, the following code will produce the result see in table \ref{tb:sampletable}:
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Sample of a Basic Table}]
|
||||
\begin{table}
|
||||
\caption{Sample of a Basic Table in \LaTeX{} }
|
||||
\label{tb:sampletable}
|
||||
\begin{tabular}{ | c l r | }
|
||||
\hline
|
||||
beans & greens & tomatoes \\
|
||||
\hline
|
||||
potatoes & lamb & rams \\
|
||||
\hline
|
||||
hogs & maws & chicken turkey \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{table}
|
||||
\caption{Sample of a Basic Table in \LaTeX{} }
|
||||
\label{tb:sampletable}
|
||||
\begin{tabular}{ | c l r | }
|
||||
\hline
|
||||
beans & greens & tomatoes \\
|
||||
\hline
|
||||
potatoes & lamb & rams \\
|
||||
\hline
|
||||
hogs & maws & chicken turkey \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
Note that I did not say ``in the table below'' because the \texttt{table} container is a float. That is, it allows \LaTeX{} to find what it thinks is the best location for the table in your document. This is often a point of confusion for beginners, because they assume that the table will appear where in their document where it appears in their file.
|
||||
|
||||
The code is fairly straightforward:
|
||||
|
||||
\begin{itemize}[noitemsep]
|
||||
\item \texttt{caption} provides a title for the table. See chapter \ref{ch:referencing} for more information.
|
||||
\item \verb+\begin{tabular}+ begins the actual table we are building.
|
||||
\item \verb+{ | c l r | }+ defines the table's columns and vertical lines. ``c'' is a center-aligned column, ``l'' a left-aligned column, and ``r'' a right-aligned column. The two pipe symbols represent vertical lines on either side of the table. (We could also put them between columns, as well.)
|
||||
\item \verb+\hline+ inserts a horizontal line.
|
||||
\item \verb+\\+ ends a row.
|
||||
\end{itemize}
|
||||
|
||||
Typesetting tables in \LaTeX{} is straightforward, but it is not without its issues. In particular, tables that float can cause a lot of issues for users, and controlling the width of both the table and individual columns can be a challenge. However, if you do not wrap your table in a \texttt{table}, you cannot add a caption, as \LaTeX{} will give you a ``caption outside float'' error. As you can see in our sample table, \LaTeX{} has automatically sized the columns and table to fit our content, but that does not always make for an aesthetically pleasing table. It can also be difficult to easily break lines in a table cell, for which you would need to use \verb+\newline+ or add the \texttt{makecell} package.
|
||||
|
||||
There are solutions to this, and Klaus Höppner pointed out many of them in his ``Typesetting tables with \LaTeX{}'' article, which I recommend reading. (You can find it at \kref{https://tug.org/TUGboat/tb28-3/tb90hoeppner.pdf}{https://tug.org/TUGboat/tb28-3/tb90hoeppner.pdf}.)
|
||||
|
||||
\section{The \texttt{tabularray} Package}
|
||||
|
||||
I have found a solution to all of my table problems by using the \texttt{tabularray} package, which seems to combine the best features of all the various table packages out there.
|
||||
|
||||
\texttt{tabularray} offers two table environments: \texttt{tblr} and \texttt{longtblr}. I prefer the latter as it both offers the option to add a caption, and will break across pages, adding a very nice ``continued on next page'' message. (See table \ref{tb:expsizcom} in chapter \ref{ch:math} for an example.)
|
||||
|
||||
This is the basic format of a \texttt{longtblr} table that I use on a regular basis:
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{longtblr Example}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {Sample \texttt{longtblr} Table},
|
||||
label = {tbl:longtblr}
|
||||
]{
|
||||
width = {\textwidth},
|
||||
colspec = { X[1,l] X[1,l] },
|
||||
hlines = {0.75pt,solid},
|
||||
vline{1,3} = {0.75pt,solid},
|
||||
rows = {5mm, m, rowsep=1.5pt}
|
||||
}
|
||||
Lemons & Limes \\
|
||||
Oranges & Grapefruit
|
||||
\end{longtblr}
|
||||
\end{Verbatim}
|
||||
|
||||
\noindent{}which produces the table we see below:
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {Sample \texttt{longtblr} Table},
|
||||
label = {tbl:longtblr}
|
||||
]{
|
||||
width = {\textwidth},
|
||||
colspec = { X[1,l] X[1,l] },
|
||||
hlines = {0.75pt,solid},
|
||||
vline{1,3} = {0.75pt,solid},
|
||||
rows = {5mm, m, rowsep=1.5pt}
|
||||
}
|
||||
Lemons & Limes \\
|
||||
Oranges & Grapefruit
|
||||
\end{longtblr}
|
||||
|
||||
Most of this should be fairly straightforward. \texttt{caption} and \texttt{label} provide a caption (which will be carried over onto the next page should the table extend over to a second page or beyond) and a label we can refer to later.
|
||||
|
||||
The \texttt{width} does not need to specified explicitly; if you omit it, the table will be the full width of your page. I include it in my template because I may want to make a table less than a full page width, as I do in table \ref{tb:localsizecommands} on page \pageref{tb:localsizecommands}.
|
||||
|
||||
The \texttt{colspec} requires some explaining. Although \texttt{tabularray} supports ordinary \texttt{c}, \texttt{l}, and \texttt{r} columns, it also supports an \texttt{X}-type column which allows you to control the width. I am specifying a width of 1 for each column, so both columns will have the same width. If I wanted one column to be twice as wide as the other one, I could simply change its width to 2. (Unlike the \texttt{tabularx} package, there is no need to ensure that your width values add up to the number of columns. You could easily do this as a percentage by specifying a width of 67 for the wider column and 33 for the narrower column.)
|
||||
|
||||
To specify horizontal lines between each row, I only need to add \verb+hlines = {0.+ \verb+75pt,solid}+. This adds a solid line (other options are \texttt{dashed} and \texttt{dotted}) between each row and at the top and bottom of the table.
|
||||
|
||||
To specify vertical lines, I added \verb+vline{1,3} = {0.75pt,solid}+. Note that this is singular (\texttt{vline}) rather than plural (\texttt{hlines}). That's because I only want the first and third vertical lines to appear in my table. (The \texttt{booktabs} package recommends against using vertical lines inside your table, and I tend to agree in most cases. This document certainly contains some exceptions.) If I had five columns, and only wanted to have vertical lines on the outside of the table, I would specify \verb+vline{1,6}+.
|
||||
|
||||
You can also specify line colors by using the color codes listed in the \texttt{ninecolors} package documentation. To specify blue horizontal lines, you would use something like \verb+hlines = {0.75pg,solid,blue7}+.
|
||||
|
||||
The rows are specified with \verb+rows = {5mm, m, rowsep=1.5pt}+. \texttt{5mm} specifies a minimum height of 5 millimeters for each row. \texttt{m} specifies that the content should be centered vertically in each row. (Other options are \texttt{t} to put everything at the top and \texttt{b} to put everything at the bottom.) \texttt{rowsep} specifies vertical padding for each row. (Columns have a similar feature called, naturally enough, \texttt{colspec}.)
|
||||
|
||||
\subsection{Changing Row Types in \texttt{tabularray}}
|
||||
|
||||
The advantage of this system is that we can ensure that all our rows are typeset the same. However, we can also use a \texttt{rowspec} with a primitive \texttt{Q}-type row to change rows. For example, this code:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
rowspec = {Q[t], Q[b]}
|
||||
\end{Verbatim}
|
||||
|
||||
\noindent{}allows us to have two rows with different qualities. In this case, the first row would be vertically aligned to the top of each cell, while the second row would be vertically aligned to the bottom of each cell.
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{tabularray Example with rowspec}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with \texttt{rowspec}},
|
||||
label = {tb:rowspec}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,l] X[2,l] },
|
||||
rowspec = { Q[cyan7] Q[yellow3] },
|
||||
hlines, vlines
|
||||
}
|
||||
This is some incredibly long text that is going to wrap around in this cell. & This is at the top.\\
|
||||
This is at the bottom & This is some more incredibly long text that is going to wrap around in this cell. Gosh, this is an awful lot of meaningless text.
|
||||
\end{longtblr}
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with \texttt{rowspec}},
|
||||
label = {tb:rowspec}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,l] X[2,r] },
|
||||
rowspec = { Q[t,azure9] Q[b,yellow9] },
|
||||
hlines, vlines
|
||||
}
|
||||
This is some incredibly long text that is going to wrap around in this cell. & This is at the top.\\
|
||||
This is at the bottom & This is some more incredibly long text that is going to wrap around in this cell. Gosh, this is an awful lot of meaningless text.
|
||||
\end{longtblr}
|
||||
|
||||
Note that we also added color to each row. (Colors could be added to each column in the \texttt{colspec} as well.) The \texttt{tabularray} package does recommend to use \texttt{colspec} for horizontal alignment, and \texttt{rowspec} for vertical alignment.
|
||||
|
||||
We've also simplified the line specifcation by using \texttt{hlines, vlines}. And we've made the table narrower by specifying \Verb+width = {0.6\textwidth}+.
|
||||
|
||||
The disadvantage of using \texttt{rowspec} is that we must include every row in the table, so if we have long tables, we will end up with a fairly extensive \texttt{rowspec}.
|
||||
|
||||
\subsection{Multiline Cells in \texttt{tabularray}}
|
||||
|
||||
If you want to break text in a cell, you can surround the cell contents with curly braces and use \Verb+\\+ where you want the break.
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{tabularray Example with multiline cells}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multiline Cells},
|
||||
label = {tb:multiline}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
{ Red \\ Green \\ Blue } & Red Green Blue\\
|
||||
{ Cyan \\ Magenta \\ Yellow } & Cyan Magenta Yellow\\
|
||||
\end{longtblr}
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multiline Cells},
|
||||
label = {tb:multiline}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
{ Red \\ Green \\ Blue } & Red Green Blue\\
|
||||
{ Cyan \\ Magenta \\ Yellow } & Cyan Magenta Yellow\\
|
||||
\end{longtblr}
|
||||
|
||||
\subsection{Spanning Multiple Rows or Columns in \texttt{tabularray}}
|
||||
|
||||
It is also possible to have cells span multiple rows or columns by using the \Verb+\SetCell+ command.
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{\texttt{tabularray} Table with Multi Rows and Columns}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multi Rows and Columns},
|
||||
label = {tb:multirow}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] X[1,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
\SetCell[r=2]{l}Pasta & \SetCell[c=2]{r} Sauce & Meatballs \\
|
||||
Fish & Chips & Mushy Peas \\
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multi Rows and Columns},
|
||||
label = {tb:multirow}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] X[1,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
\SetCell[r=2]{l}Pasta & \SetCell[c=2]{r} Sauce & Meatballs \\
|
||||
Fish & Chips & Mushy Peas \\
|
||||
\end{longtblr}
|
||||
|
||||
The typical way of doing this requires use of the \Verb+\multicolmn+ command (which requires you to load the \texttt{multirow} package), and it requires that omitted cells must be empty. This is not the case with \texttt{tabularray}, however. As you can see from the source code, the words ``Meatballs'' and ``Fish'' have simply been omitted from the resulting table. We are also able to change the horizontal alignment by specifying it after we specify how many rows or columns to span.
|
||||
|
||||
|
||||
\chapter{Formatting Pages}
|
||||
|
||||
\section{Page Size}
|
||||
@ -1133,6 +907,233 @@ produces this example:
|
||||
|
||||
\noindent{}I can probably live with that.
|
||||
|
||||
|
||||
\chapter{Tables}
|
||||
|
||||
Tables in \LaTeX{} are often confusing to beginners, because there are two environments that are not quite what they seem. The \texttt{tabular} environment is used to create a table, while the \texttt{table} environment is a float that surrounds the table and can contain a caption.
|
||||
|
||||
\section{Built-in Table Environments}
|
||||
|
||||
For example, the following code will produce the result see in table \ref{tb:sampletable}:
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Sample of a Basic Table}]
|
||||
\begin{table}
|
||||
\caption{Sample of a Basic Table in \LaTeX{} }
|
||||
\label{tb:sampletable}
|
||||
\begin{tabular}{ | c l r | }
|
||||
\hline
|
||||
beans & greens & tomatoes \\
|
||||
\hline
|
||||
potatoes & lamb & rams \\
|
||||
\hline
|
||||
hogs & maws & chicken turkey \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{table}
|
||||
\caption{Sample of a Basic Table in \LaTeX{} }
|
||||
\label{tb:sampletable}
|
||||
\begin{tabular}{ | c l r | }
|
||||
\hline
|
||||
beans & greens & tomatoes \\
|
||||
\hline
|
||||
potatoes & lamb & rams \\
|
||||
\hline
|
||||
hogs & maws & chicken turkey \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
Note that I did not say ``in the table below'' because the \texttt{table} container is a float. That is, it allows \LaTeX{} to find what it thinks is the best location for the table in your document. This is often a point of confusion for beginners, because they assume that the table will appear where in their document where it appears in their file.
|
||||
|
||||
The code is fairly straightforward:
|
||||
|
||||
\begin{itemize}[noitemsep]
|
||||
\item \texttt{caption} provides a title for the table. See chapter \ref{ch:referencing} for more information.
|
||||
\item \verb+\begin{tabular}+ begins the actual table we are building.
|
||||
\item \verb+{ | c l r | }+ defines the table's columns and vertical lines. ``c'' is a center-aligned column, ``l'' a left-aligned column, and ``r'' a right-aligned column. The two pipe symbols represent vertical lines on either side of the table. (We could also put them between columns, as well.)
|
||||
\item \verb+\hline+ inserts a horizontal line.
|
||||
\item \verb+\\+ ends a row.
|
||||
\end{itemize}
|
||||
|
||||
Typesetting tables in \LaTeX{} is straightforward, but it is not without its issues. In particular, tables that float can cause a lot of issues for users, and controlling the width of both the table and individual columns can be a challenge. However, if you do not wrap your table in a \texttt{table}, you cannot add a caption, as \LaTeX{} will give you a ``caption outside float'' error. As you can see in our sample table, \LaTeX{} has automatically sized the columns and table to fit our content, but that does not always make for an aesthetically pleasing table. It can also be difficult to easily break lines in a table cell, for which you would need to use \verb+\newline+ or add the \texttt{makecell} package.
|
||||
|
||||
There are solutions to this, and Klaus Höppner pointed out many of them in his ``Typesetting tables with \LaTeX{}'' article, which I recommend reading. (You can find it at \kref{https://tug.org/TUGboat/tb28-3/tb90hoeppner.pdf}{https://tug.org/TUGboat/tb28-3/tb90hoeppner.pdf}.)
|
||||
|
||||
\section{The \texttt{tabularray} Package}
|
||||
|
||||
I have found a solution to all of my table problems by using the \texttt{tabularray} package, which seems to combine the best features of all the various table packages out there.
|
||||
|
||||
\texttt{tabularray} offers two table environments: \texttt{tblr} and \texttt{longtblr}. I prefer the latter as it both offers the option to add a caption, and will break across pages, adding a very nice ``continued on next page'' message. (See table \ref{tb:expsizcom} in chapter \ref{ch:math} for an example.)
|
||||
|
||||
This is the basic format of a \texttt{longtblr} table that I use on a regular basis:
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{longtblr Example}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {Sample \texttt{longtblr} Table},
|
||||
label = {tbl:longtblr}
|
||||
]{
|
||||
width = {\textwidth},
|
||||
colspec = { X[1,l] X[1,l] },
|
||||
hlines = {0.75pt,solid},
|
||||
vline{1,3} = {0.75pt,solid},
|
||||
rows = {5mm, m, rowsep=1.5pt}
|
||||
}
|
||||
Lemons & Limes \\
|
||||
Oranges & Grapefruit
|
||||
\end{longtblr}
|
||||
\end{Verbatim}
|
||||
|
||||
\noindent{}which produces the table we see below:
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {Sample \texttt{longtblr} Table},
|
||||
label = {tbl:longtblr}
|
||||
]{
|
||||
width = {\textwidth},
|
||||
colspec = { X[1,l] X[1,l] },
|
||||
hlines = {0.75pt,solid},
|
||||
vline{1,3} = {0.75pt,solid},
|
||||
rows = {5mm, m, rowsep=1.5pt}
|
||||
}
|
||||
Lemons & Limes \\
|
||||
Oranges & Grapefruit
|
||||
\end{longtblr}
|
||||
|
||||
Most of this should be fairly straightforward. \texttt{caption} and \texttt{label} provide a caption (which will be carried over onto the next page should the table extend over to a second page or beyond) and a label we can refer to later.
|
||||
|
||||
The \texttt{width} does not need to specified explicitly; if you omit it, the table will be the full width of your page. I include it in my template because I may want to make a table less than a full page width, as I do in table \ref{tb:localsizecommands} on page \pageref{tb:localsizecommands}.
|
||||
|
||||
The \texttt{colspec} requires some explaining. Although \texttt{tabularray} supports ordinary \texttt{c}, \texttt{l}, and \texttt{r} columns, it also supports an \texttt{X}-type column which allows you to control the width. I am specifying a width of 1 for each column, so both columns will have the same width. If I wanted one column to be twice as wide as the other one, I could simply change its width to 2. (Unlike the \texttt{tabularx} package, there is no need to ensure that your width values add up to the number of columns. You could easily do this as a percentage by specifying a width of 67 for the wider column and 33 for the narrower column.)
|
||||
|
||||
To specify horizontal lines between each row, I only need to add \verb+hlines = {0.+ \verb+75pt,solid}+. This adds a solid line (other options are \texttt{dashed} and \texttt{dotted}) between each row and at the top and bottom of the table.
|
||||
|
||||
To specify vertical lines, I added \verb+vline{1,3} = {0.75pt,solid}+. Note that this is singular (\texttt{vline}) rather than plural (\texttt{hlines}). That's because I only want the first and third vertical lines to appear in my table. (The \texttt{booktabs} package recommends against using vertical lines inside your table, and I tend to agree in most cases. This document certainly contains some exceptions.) If I had five columns, and only wanted to have vertical lines on the outside of the table, I would specify \verb+vline{1,6}+.
|
||||
|
||||
You can also specify line colors by using the color codes listed in the \texttt{ninecolors} package documentation. To specify blue horizontal lines, you would use something like \verb+hlines = {0.75pg,solid,blue7}+.
|
||||
|
||||
The rows are specified with \verb+rows = {5mm, m, rowsep=1.5pt}+. \texttt{5mm} specifies a minimum height of 5 millimeters for each row. \texttt{m} specifies that the content should be centered vertically in each row. (Other options are \texttt{t} to put everything at the top and \texttt{b} to put everything at the bottom.) \texttt{rowsep} specifies vertical padding for each row. (Columns have a similar feature called, naturally enough, \texttt{colspec}.)
|
||||
|
||||
\subsection{Changing Row Types in \texttt{tabularray}}
|
||||
|
||||
The advantage of this system is that we can ensure that all our rows are typeset the same. However, we can also use a \texttt{rowspec} with a primitive \texttt{Q}-type row to change rows. For example, this code:
|
||||
|
||||
\begin{Verbatim}[]
|
||||
rowspec = {Q[t], Q[b]}
|
||||
\end{Verbatim}
|
||||
|
||||
\noindent{}allows us to have two rows with different qualities. In this case, the first row would be vertically aligned to the top of each cell, while the second row would be vertically aligned to the bottom of each cell.
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{tabularray Example with rowspec}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with \texttt{rowspec}},
|
||||
label = {tb:rowspec}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,l] X[2,l] },
|
||||
rowspec = { Q[cyan7] Q[yellow3] },
|
||||
hlines, vlines
|
||||
}
|
||||
This is some incredibly long text that is going to wrap around in this cell. & This is at the top.\\
|
||||
This is at the bottom & This is some more incredibly long text that is going to wrap around in this cell. Gosh, this is an awful lot of meaningless text.
|
||||
\end{longtblr}
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with \texttt{rowspec}},
|
||||
label = {tb:rowspec}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,l] X[2,r] },
|
||||
rowspec = { Q[t,azure9] Q[b,yellow9] },
|
||||
hlines, vlines
|
||||
}
|
||||
This is some incredibly long text that is going to wrap around in this cell. & This is at the top.\\
|
||||
This is at the bottom & This is some more incredibly long text that is going to wrap around in this cell. Gosh, this is an awful lot of meaningless text.
|
||||
\end{longtblr}
|
||||
|
||||
Note that we also added color to each row. (Colors could be added to each column in the \texttt{colspec} as well.) The \texttt{tabularray} package does recommend to use \texttt{colspec} for horizontal alignment, and \texttt{rowspec} for vertical alignment.
|
||||
|
||||
We've also simplified the line specifcation by using \texttt{hlines, vlines}. And we've made the table narrower by specifying \Verb+width = {0.6\textwidth}+.
|
||||
|
||||
The disadvantage of using \texttt{rowspec} is that we must include every row in the table, so if we have long tables, we will end up with a fairly extensive \texttt{rowspec}.
|
||||
|
||||
\subsection{Multiline Cells in \texttt{tabularray}}
|
||||
|
||||
If you want to break text in a cell, you can surround the cell contents with curly braces and use \Verb+\\+ where you want the break.
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{tabularray Example with multiline cells}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multiline Cells},
|
||||
label = {tb:multiline}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
{ Red \\ Green \\ Blue } & Red Green Blue\\
|
||||
{ Cyan \\ Magenta \\ Yellow } & Cyan Magenta Yellow\\
|
||||
\end{longtblr}
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multiline Cells},
|
||||
label = {tb:multiline}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
{ Red \\ Green \\ Blue } & Red Green Blue\\
|
||||
{ Cyan \\ Magenta \\ Yellow } & Cyan Magenta Yellow\\
|
||||
\end{longtblr}
|
||||
|
||||
\subsection{Spanning Multiple Rows or Columns in \texttt{tabularray}}
|
||||
|
||||
It is also possible to have cells span multiple rows or columns by using the \Verb+\SetCell+ command.
|
||||
|
||||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{\texttt{tabularray} Table with Multi Rows and Columns}]
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multi Rows and Columns},
|
||||
label = {tb:multirow}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] X[1,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
\SetCell[r=2]{l}Pasta & \SetCell[c=2]{r} Sauce & Meatballs \\
|
||||
Fish & Chips & Mushy Peas \\
|
||||
\end{Verbatim}
|
||||
|
||||
\begin{longtblr}
|
||||
[
|
||||
caption = {\texttt{tabularray} Table with Multi Rows and Columns},
|
||||
label = {tb:multirow}
|
||||
]{
|
||||
width = {0.6\textwidth},
|
||||
colspec = { X[1,c] X[2,c] X[1,c] },
|
||||
rows = {5mm, m, rowsep=1.5pt},
|
||||
hlines, vlines
|
||||
}
|
||||
\SetCell[r=2]{l}Pasta & \SetCell[c=2]{r} Sauce & Meatballs \\
|
||||
Fish & Chips & Mushy Peas \\
|
||||
\end{longtblr}
|
||||
|
||||
The typical way of doing this requires use of the \Verb+\multicolmn+ command (which requires you to load the \texttt{multirow} package), and it requires that omitted cells must be empty. This is not the case with \texttt{tabularray}, however. As you can see from the source code, the words ``Meatballs'' and ``Fish'' have simply been omitted from the resulting table. We are also able to change the horizontal alignment by specifying it after we specify how many rows or columns to span.
|
||||
|
||||
|
||||
\chapter{Math in \LaTeX{}}\label{ch:math}
|
||||
|
||||
\LaTeX{} has a couple of different environments that are useful for typesetting math (\texttt{align} and \texttt{array}, but they get a little beyond what I want to cover here. In addition, there are other packages (in particular \texttt{amsmath} and \texttt{mathtools}) that greatly extend the power of LaTeX to handle mathematical typesettings, but again, they are beyond the scope of this book.
|
||||
|
Loading…
Reference in New Issue
Block a user