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}
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}
I have a table with 3 columns where the first 2 columns are pictures and the 3rd is my comment on those pictures, but the comment "drowns", it is down at the bottom of the cell.
I have tried with m{2cm} instead of c:
\begin{tabularx}{\textwidth}{c c m{2cm}}
but no change.
\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
\begin{tabularx}{\textwidth}{c c c}
\textbf{O-Na} & \textbf{Na-Y} & \textbf{Comments} \\
\includegraphics[width=0.3\linewidth]{pic1.png} &
\includegraphics[width=0.3\linewidth]{pic2.png} &
My comments. \\
\end{tabularx}
\end{table}
My text is at the bottom of the cell.
The graphbox provides the handy align=c option to vertically centre images:
\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{graphbox}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\begin{document}
\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
\begin{tabularx}{\textwidth}{XXX}
\thead{O-Na} & \thead{Na-Y} & \thead{Comments} \\
\includegraphics[width=\linewidth,align=c]{example-image-duck} &
\includegraphics[width=\linewidth,align=c]{example-image-duck} &
My comments. \\
\end{tabularx}
\end{table}
\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!
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?
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.