I am trying to center one of the columns in a table and It says I have an extra column. The table also doesnt look correct i.e.
What it looks like:
F(t) F(s)
u(t)
1/s
e 1/(s-a)
What I expect:
F(t) F(s)
u(t) 1/s
e 1/(s-a)
I think it is because I'm trying to insert an equation in the table but I'm not sure.
Here is the code
\documentclass[12pt, letterpaper, fleqn]{article}
\usepackage{array}
\begin{document}
\begin{table}
% \setlength{\tabcolsep}{6pt}
% \renewcommand{\arraystretch}{1}
\begin{tabular}{p{0.225\textwidth} >{\centering}p{0.15\textwidth}}
\textbf{F(t)} & \textbf{F(s)} \\
\(u(t)\) & \(\frac{1}{s}\) \\
\(e^{at}\) & \(\frac{1}{s-a}\) \\
\end{tabular}
\end{table}
\end{document}
Your use of \centering to centre the column works, but it screws up the way \\ is interpreted. A correction is included in the array package documentation after using alignment switches (like \centering, \raggedright, \raggedleft, etc) using \arraybackslash:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{ p{0.225\textwidth} >{\centering\arraybackslash}p{0.15\textwidth} }
$\mathbf{F(t)}$ & $\mathbf{F(s)}$ \\
$u(t)$ & $1 / s$ \\
$e^{at}$ & $1 / (s - a)$
\end{tabular}
\end{document}
If you remove >{\centering}, then your code should compile as expected. Post a comment otherwise! Do you want any column to have centered contents?
Related
I wanted a table in latex, and the headings to be centered both horizontally and vertically within it with more vertical space than the rest of the columns. This is the code i wrote;
\begin{tabular}{| l | l | l |}\hline
\rowcolor{lightgray} \multicolumn{1}{|c|}{\large{\textsc{Vitamin}}} & \multicolumn{1}{|c|}{\large{\textsc{Use In Body}}} & \multicolumn{1}{|c|}{\large{\textsc{Deficiency Disease}}}\rule{0pt}{25pt} \rule[-25pt]{0pt}{25pt}\\\hline
\linebreak
& &
\end{tabular}
This is the result i get.
Result image
There is an extra column or something that exists after the third column. Do you know any fixes random stranger?
You need to insert the vertical rule (strut) within a column. You have defined it outside it which is causing the unexpected extensions.
\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabular}{| l | l | l |}\hline
\rowcolor{lightgray}\multicolumn{1}{|c|}{\large{\textsc{Vitamin}}} & \multicolumn{1}{c|}{\large{\textsc{Use In Body}}} & \multicolumn{1}{c|}{\large{\textsc{Deficiency Disease\rule{0pt}{25pt} \rule[-25pt]{0pt}{25pt}}}}
\\\hline
& & \\
\hline
\end{tabular}
\end{document}
You can use a single rule instead of two like this \rule[-25pt]{0pt}{50pt}. Also, notice that the 1st row is not vertically centered.
I would propose you use the tabularray package which makes managing rows and columns very easy. Also, it's more preferred for color tables with vertical lines.
Code using the tabularray package:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
hlines, vlines,
colspec=lll,
row{1}={c, m, 50pt, lightgray, font=\large\scshape},
}
Vitamin & Use In Body & Deficiency Disease\\
&&\\
\end{tblr}
\end{document}
Using the wrapfig package with a table inside a section, the table's first row is not aligned with the text that wraps it. This problem is not present when working outside of a section.
\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\section{Section}
\begin{wraptable}{l}{0pt}
\begin{tabular}{cccc}
A & B & C & D \\
E & F & G & H\\
\end{tabular}
\label{Mytable}\caption{This is my table.}
\end{wraptable}
\textbf{This bit of text should be aligned with the table's top row.}
\lipsum[2]
\end{document}
What this gives is:
Whereas ideally I'd like to get something like:
You could try to adjust \intextsep:
\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\section{Section}
{
\setlength\intextsep{-0.4ex}
\begin{wraptable}{l}{0pt}
\begin{tabular}{cccc}
A & B & C & D \\
E & F & G & H\\
\end{tabular}
\label{Mytable}\caption{This is my table.}
\end{wraptable}
\textbf{This bit of text should be aligned with the table's top row.}
\lipsum[2]
}
\end{document}
In the following commuting diagram, I would like to draw a box containing the bottom triangle defined by nodes D, E and F. Do you know how I could do that?
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}[row sep=2.5em]
& \text{A} \\
\arrow[rightarrow]{d}{R_4}\text{B} \arrow[leftarrow]{ur}{R_1}
\arrow[dashed,leftrightarrow]{rr}{R_3} && \text{C} \\
\arrow[leftrightarrow]{rd}{R_1}\text{D}\arrow[leftrightarrow]{rr}{R_3} & &
\text{E} \arrow[leftrightarrow]{ld}{R_2}\\
& \text{F} &
\end{tikzcd}
\]
\end{document}
Searching here and there, I put together the following:
\documentclass{article}
\usepackage{amsmath}
%\usepackage{tikz-cd}
\usepackage{tikz}
\usetikzlibrary{cd}
\usetikzlibrary{fit, patterns}
\begin{document}
\[
\tikz[%remember picture,
overlay]{
\filldraw[fill=yellow!50,draw=red!50!yellow] (-.5,-3.2) rectangle (3.8,-.4);
}
\begin{tikzcd}[row sep=2.5em]
& \text{A} \\
\arrow[rightarrow]{d}{R_4}\text{B} \arrow[leftarrow]{ur}{R_1}
\arrow[dashed,leftrightarrow]{rr}{R_3} && \text{C} \\[3em]
\arrow[leftrightarrow]{rd}{R_1}\text{D}\arrow[leftrightarrow]{rr}{R_3} & &
\text{E} \arrow[leftrightarrow]{ld}{R_2}\\
& \text{F} &
\end{tikzcd}
\]
\end{document}
It outputs:
I didn't edit any of your code within \[ and \], except for adding [3em] in line 18 for the sake of vertical spacing.
The style (colors, margins) may be changed up to your personal taste!
Ok so i wrote this simple code (shown below) to create an alternate colour table using \rowcolors, yet instead of just colouring the rows of the table it colours the whole row (even more than textwidth). Any help how to fix this?
begin{table}[ht]
\scriptsize
\begin{center}
\rowcolors{1}{lightgray}{white}
\caption{...}
\begin{tabular}{p{0.45\textwidth} | p{0.55\textwidth}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F \\
\end{tabular}
\end{center}
\end{table}
While 0.45\textwidth + 0.55\textwidth would seem to fit within \textwidth, each of your p-columns have an extra column separation... on both sides. To that end, you should remove them in order to make it fit within the text block boundary:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{lipsum}
\begin{document}
\begin{table}[ht]
\scriptsize\centering
\rowcolors{1}{lightgray}{white}
\caption{This is a table.}
\begin{tabular}{
p{\dimexpr0.45\textwidth-2\tabcolsep} |
p{\dimexpr0.55\textwidth-2\tabcolsep}}
Filename & Contents \\
\hline
\hline
A & B \\
C & F
\end{tabular}
\end{table}
\lipsum[1]
\end{document}
Also, don't use the center environment; use \centering instead.
I have a table as shown in this figure:
The LaTeX code for the table is:
\begin{table}
\begin{tabular}{ | c | c | }
\hline
\includegraphics[scale=0.45]{../0_1.eps} & 1.10 2.20 3.30 4.40 \\
\hline
\end{tabular}
\end{table}
I would like to make the four numbers appear in different lines inside the second cell, in order to reduce its width. I wonder how to do it?
EDIT:
I tried \linebreak,
\includegraphics[scale=0.45]{../0_1.eps} & 1.10 \linebreak 2.20 \linebreak 3.30 \linebreak 4.40 \\
But the result is the same as before i.e. without \linebreak.
EDIT:
I just tried what Rob suggested. But the result is not compact, because my intention is to reduce the size of the table. See the figure below:
Try using a p column with \par to indicate line breaks.
\begin{table}
\begin{tabular}{ | c | p{2cm} | }
\hline
\includegraphics[scale=0.45]{../0_1.eps} & 1.10\par 2.20\par 3.30\par 4.40 \\
\hline
\end{tabular}
\end{table}
Try
\begin{table}
\def\baselinestretch {}\selectfont %
% \baselineskip = 14.4pt\relax %% Uncomment this if the result is not compact.
\begin{tabular}{ | c | p{2cm} | }
\hline
$\vcenter{\hbox{\includegraphics[scale=0.45]{../0_1.eps}}$ &
$\vcenter{\strut 1.10\par 2.20\par 3.30\par 4.40\strut}$ \\
\hline
\end{tabular}
\end{table}
You can use mathmode in the last cell: ${1.10 \atop 2.20 } \atop {3.30 \atop 4.40}$.
That will be nice and small...
If you want it bigger, cf. Typesetting fraction terms to be larger in an equation.
I would look into using the multirow package. Details on spanning multiple columns/rows are here.
\linebreak ? sometimes works for me in tables and sometimes doesn't.
Minipage might accomplish this.
\begin{minipage}{3in}
% escape the weirdness of tabular with your own mini page
1.10 \\ 2.20 \\ 3.30 \\ 4.40
\end{minipage}
You may also want a \strut on the first and last lines, to prevent it abutting any tabular borders.