Is it possible to vertically center multiple columns in a table? - alignment

I've found an example here but that only centers one column and I can't really adapt it to my needs. What I'd like is something like this:

You'll need \usepackage{array} to do this.
From what I can gather, you're looking at the m{} alignment, which wraps a paragraph at the specified point value, and vertically aligns the text to the middle of the field. For example, something like this:
\begin{tabular}{|m{2cm}|m{1ex}|m{1ex}|m{1ex}} \hline
& x1 & x2 & x3 \\\hline
Long Label & 1 & 0 & 1 \\\hline
Long Label & 0 & 1 & 1 \\\hline
\end{tabular}

Try this:
\begin{tabular}{|m{3.5em}|b{1em}|b{1em}|b{1em}|}
\hline
%% row 1
&x1
&x2
&x3
\\\hline
%% row 2
Long Label
&1
&0
&1
\\\hline
%% row 3
Long Label
&1
&0
&1
\\\hline
\end{tabular}
For more info on table formatting see http://en.wikibooks.org/wiki/LaTeX/Tables
EDIT: changed c to b{}

Related

Missing Vertical Line Table

I have code for a latex table, but it seems it's missing the right vertical line in my title row. Am I missing something small? Here's my code:
\begin{center}
\begin{tabular}{||c c c||}
\hline
\textbf{Table Title} \\ [0.5ex]
\hline\hline
\hline
Col A & Col B & Col C \\
\hline\hline
1 & 0.39 & 6.16 \\
\hline
2 & 0.40 & 4.13 \\
\hline
3 & 0.28 & 0.12 \\
\hline
\end{tabular}
\end{center}
and this is the table I get:
As the row of interest spans three columns, you might want to use \multicolumn command: \multicolumn{# of columns}{alignment}{text}. So try replacing
\textbf{Table Title} \\ [0.5ex]
with
\multicolumn{3}{||l||}{\textbf{Table Title}}\\
Technically talking, the vertical line on the right of the first row does not appear because the table is set to have three cells per row but that first row only has one cell.
The two & in the line of code below would separate three cells within that row, allowing the vertical line on the right to show:
\textbf{Table Title} & & \\ [0.5ex]
Anyway, the solution using multicolumn shown in the other answer is to be preferred: this command allows the content of the first row to span along the three columns, less likeky influencing the overall width of the table.

LaTex table corner cell line not showing

I'm using Overleaf to write a report. I can't seem to get the format just right for the top right corner cell.
I would also like to center "Correlation coefficient"
\begin{table}[h]
\caption{Correlation coefficient between force plate data and kinematic model data}
\label{IMUvsVB}
\begin{center}
\begin{tabular}{|c||c||c|}
\hline
\textbf{Ground reaction} & \multicolumn{2}{l}{\textbf{Correlation coefficient}} \\
\cline{2-3}
& \textbf{IMU based kinematics} & \textbf{Vision based kinematics}\\
\hline
Anteroposterior & 0.91 & 0.96\\
Mediolateral & 0.80 & 0.79\\
Vertical & 0.97 & 0.99\\
Frontal & 0.64 & 0.66\\
Sagittal & 0.91 & 0.94\\
Transverse & 0.82 & 0.84\\
\hline
\end{tabular}
\end{center}
\end{table}
Substitute
\textbf{Ground reaction} & \multicolumn{2}{l}{\textbf{Correlation coefficient}} \\
with
\textbf{Ground reaction} & \multicolumn{2}{c|}{\textbf{Correlation coefficient}} \\
The \multicolumn command needs 3 inputs:
The 1st one is the number of columns to be spanned.
The 2nd is the formatting of the cell (l for left, c for center and r for right). Here you can add also | for a single vertical line or even || for a double vertical line.
The 3rd one is the content of the cell.
Have a look at the documentation here if you need more insights on the usage of \multicolumn.

How to insert a table with a \raggedleft text and how to fix the hole table in the left

I am a new with Latex and I would like to correct this table:
I need the texts to be on left
I need to shift the hole table
in the left also so it will be clearer
To align the whole object (table) to left, use \begin{flushleft} ... \end{flushleft}.
To align the text in cells in a column to left, center or right, use 'l', 'c' or 'r' in the description of your tabular, like bellow.
\begin{flushleft}
\begin{table}
\begin{tabular}{lcrrr}
\hline
Minta & pH & time & d & eltáv.\\
\hline
e-Ni-NA1 & ? & 7100 & 18 & Marás \\
e-Ni-NA2 & ? & 7100 & 18 & Marás \\
e-Ni-NA3 & 3.3 & 7200 & 18 & Cellux \\
\hline
\end{tabular}
\end{table}
\end{flushleft}

Multirow cells in TeX tables

I'm trying to make a table that is very similar to the first table of Cremona's book on Elliptic Curves, however occasionally I want to have cells that span multiple row. I am not opposed to using LaTeX packages, but I have not been able to figure out how to use variable width columns which respect vertical bars around centered columns.
(This code from Wikibooks makes the centered columns appear to be right aligned
\begin{tabular*}{0.75\textwidth}{#{\extracolsep{\fill}} | c | c | c | r | }
\hline
label 1 & label 2 & label 3 & label 4 \\
\hline
item 1 & item 2 & item 3 & item 4 \\
\hline
\end{tabular*}
)
Any help would be greatly appreciated.
Simply use the tabular environment instead of tabular*, and your example above will have all centered cols.
I give the following example in order to show both centered multicols and centered multirows (using package multirow):
\begin{tabular}{ | c | c | c | r | }
\hline
label 1 & label 2 & label 3 & label 4 \\
\hline
\multicolumn{2}{|c|}{\textbf{Name of the SLA parameter $\pi$}} &
\multicolumn{2}{|c|}{\textbf{Name of the SLA parameter $\pi$}} \\
\hline
\multirow{2}{*}{item 1} & item 2 & item 3 & item 4\\
& item 2 & item 3 & item 4 \\
\hline
item 1 & item 2 & item 3 & item 4 \\
\hline
\end{tabular}
All columns and rows meant to be centered are centered.

Latex: Problem with Multirow

I am creating a table with mulitrow but I am getting a problem. As far as I understand, this is the form of the multirow:
\multirow{count}{alignment}{content}
where count is the number of rows to merge, alignment is either l, c, r, or *, and content is the content of the row. I tried the following:
\multirow{3}{*}{Framing}
but I am getting a problem. Rather than seeing the word "Framing" in the cell, I see "3*Framing" which gives the indication that the \multirow element isn't working. Any idea?
Also, how is it possible to align a text in a cell vertically?
UPDATE:
I thought the \usepackage{multirow} would solve it, but I still see problems:
First, I can't make vertical alignments.
Second, I get some strange thing with the "Framing" cell. Instead of getting "Framing" aligned to the left, I get one virtual row containing the letter "l" and then after two virtual rows I get the word "Framing"!! It is something like this:
______________
| l |
| |
| Framing |
| |
| |
| |
| |
______________
This is my table for those who asked about it:
\begin{table*}\tiny
\centering
\begin{tabular}{|c|c|c|c|c|p{2in}|}
\hline
Rule & Factor & Best Value & \Delta_t & \Delta_{do} & Comments \\
\hline
% Diagonal Dominance Rule
\multirow{3}{*}{Diagonal Dominance} & Line Angle & 45 & 15 & 30 & The angle between the prominent line of the object and
the diagonal lines \\ % TODO: What object? Make sure it is clear.
& Line Distance & 0 & 0.25 & 1 & The distance, in screen coordinates, from the
prominent line of the object to the diagonal lines. \\ % TODO: Need to define screen coordinates
& Corner Distances & 0 & 0.1 & 0.7 & The distance, in screen coordinates, from the
end of the prominent line of the object to the corners of the screen. \\
\hline
% Framing Rule
\multirow{4}{l}{Framing} & Left Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance between the
left side of the frame covering the object and the left or the right side of the intended frame, whichever closer. \\
& Right Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance between the
right side of the frame covering the object and the left or the right side of the intended frame, whichever closer. \\
& Top Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance between the
top side of the frame covering the object and the upper or the lower side of the intended frame, whichever closer. \\
& Bottom Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance between the
bottom side of the frame covering the object and the upper or the lower side of the intended frame, whichever closer. \\
\hline
\end{tabular}
\caption{The factors of each rule and their parameters.}
\label{table:factors}
\end{table*}
Regards,
Rafid
Did you put \usepackage{multirow} at the beginning of your document?
There are probably good examples out there to follow. I've never used this package but in a short time (seconds) was able to find this PAGE via google. Does following along with that example help you?
Update: after seeing your actual table, I hate to say it but think your spacing glitch is due to the spill over in the "comments" column into multiple lines. I truncated your comments and got this (column 1 is now vertically centered as desired):
\begin{table*}\tiny
\centering
\begin{tabular}{|c|c|c|c|c|p{3cm}|}
\hline
Rule & Factor & Best Value & \Delta_t & \Delta_{do} & Comments \\
\hline
% Diagonal Dominance Rule
\multirow{3}{*}{Diagonal Dominance} & Line Angle & 45 & 15 & 30 & The angle between... \\
& Line Distance & 0 & 0.25 & 1 & The distance, in... \\
& Corner Distances & 0 & 0.1 & 0.7 & The distance, in... \\
\hline
% Framing Rule
\multirow{4}{*}{Framing} & Left Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance... \\
& Right Distance & 0 & ${Frame Width}*5\%$ & ${Frame Width}*25\%$ & The distance... \\
& Top Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance... \\
& Bottom Distance & 0 & ${Frame Height}*5\%$ & ${Frame Height}*25\%$ & The distance... \\
\hline
\end{tabular}
\caption{The factors of each rule and their parameters.}
\label{table:factors}
\end{table*}
Regarding the {l} argument, I think the link I posted originally is perhaps wrong. LaTeX spits out some errors for me when I try replacing * with l for the \multirow argument. I get this on a test table:
! Missing number, treated as zero.
<to be read again>
l
l.12 \multirow{4}{l}{Batch}
& MM & Min-Min \\
! Illegal unit of measure (pt inserted).
<to be read again>
l
l.12 \multirow{4}{l}{Batch}
& MM & Min-Min \\
After finding THIS, I think the second argument in \multirow is not for an alignment but for a width. The LyX wiki linked says the format is like so:
\multirow{number of rows}{cell width}{cell entry}
We've been assuming that {cell width} was actuall {alignment} and I think the link from earlier makes that confusing. See the note at the LyX wiki about spacing; you can use the following where needed to make it do your bidding:
\renewcommand{\multirowsetup}{\centering}
And replace \centering with \raggedleft or \raggedright where needed. I still think you're going to run into trouble with the multiple lines. I've at least shown that ditching them makes the spacing work as desired... how to force them to be centered with your default example is beyond me, I'm afraid. But perhaps now you know where the problem lies?
I guess if you really, really, really wanted to you could split your sentence up, figure out how many rows it takes, and adjust your \multirow argument accordingly for the increase in rows. Though you'd also probably need a nested multirow structure:
| | item 1, 2 rows | comment 1 line 1 |
| multirow, 4 rows | | comment 1 line 2 (spill over) |
| | item 2, 2 rows | comment 2 line 1 |
| | | comment 2 line 2 (spill over) |
Does that make sense? Column 1 would span all rows for its section, subsequent rows would span the number of rows required by the split up comments, and each line needed by the comments (some take up 3 or 4) would be on their own separate lines and just appear to be continuous. Not sure if the sentence spacing would look weird, though.
Nuff rambling. There's your food for thought.
One Last Update: One last hope way to go about this might be with TikZ tables. Essentially, your nodes are like "cells." Then just put them together and make it look like a table. Perhaps a horrible proposal, but I assure you that you'll have all the flexibility you need with cell spacing and such. Some ideas:
Fancy Tables 1
Fancy Tables 2
Periodic table in TikZ which might give you some insight about how to do this a bit better than the first two?
Wild guess: You're getting undefined control sequence: multirow because you're lacking a \usepackage{multirow} in the preamble?
Yes, you need the multirow package.
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\begin{tabular}{l||c|r}
Header 1 & Header 2 & Header 3 \\
\multirow{2}{*}{Hello} & stuff & stuff \\
& Body 2 & Body 3
\end{tabular}
\end{table}
\end{document}
EDIT after edits to question: I got two errors:
\multirow{4}{l}{Framing}. I changed to \multirow{4}{*}{Framing}
Delta_t changed to $Delta_t$.
Otherwise, everything seems fine. You may want to ask tex.stackexchange.com, too.

Resources