I am creating a table using tabularx package, and adding figtext and caption in the table package. I want both the footnote and the caption below the table, but as soon as I add a caption, the footnotes disappear. My code is as below:
The main.tex file has the below code
\documentclass[12pt]{article}
\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,color,setspace,sectsty,comment,footmisc,caption,pdflscape,subfigure,array,hyperref,booktabs,dcolumn,threeparttable, adjustbox,apacite,dirtytalk,multirow,tabularx,booktabs}
\usepackage{ulem}
\usepackage{float}
\restylefloat{table}
\begin{frame}
\center
\input{MangoShare}
\label{mangoshare}
\end{frame}
MangoShare.tex is the reference which is being called to the main.tex.
\begin{centre}
\begin{table}[h!]
\\[-1.8ex]\hline
\hline \\\\[-1.8ex]
%\renewcommand{\arraystretch}{1.8}
\begin{tabularx}{1\textwidth}{>{\raggedright\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X}
\small
\\[-1.8ex]
& & \multicolumn{6}{c}{Percentage Share} \\\\[-1.8ex]
\cline{3-8} \\[-1.8ex]
& &\multicolumn{1}{c}{A} &\multicolumn{1}{c}{B} &\multicolumn{1}{c}{C} &\multicolumn{1}{c}{D} &\multicolumn{1}{c}{E} &\multicolumn{1}{c}{F} \\
\midrule
\multicolumn{2}{l}{Mango} & 0.58 & 0.56 & 0.92 & 0.22 & 0.72 & 0.033 \\
\tiny
\end{tabularx}
\hline
\hline %\\[-1.8ex]
\figtext{\\[-1.8ex]\emph{Notes:} Controls Used} \\[-1.8ex]
\caption{Mango Share}
\end{table}
\end{centre}
Any help on this front would be appreciated. Thanks a lot!
There are several problems:
table is a floating environment, meant to move around in your document to get a nice looking output. If you wrap it in a static environment like center or frame it can't do that!
\hline is for lines inside a tabular environment, don't use them outside (or better don't use them at all, the rules from the booktab package are much better)
it makes no sense to wrap cells into \multicolumn{1}... remove all these unnecessary commands. They can destroy alignment of your table cells
don't use \\[-1.8ex] in places where there is no active row. They'll mess up table lines etc, see Why are the vertical lines in my table different lengths?
if you want to change the font size of your tabular, do this outside.
\figtext is not defined.
\cmidrule gives better spacing than \cline
the floating specifier [h!] will most likely result in bad image placement, better use [htbp] to give latex more options
--
\documentclass[12pt]{article}
\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,color,setspace,sectsty,comment,footmisc,caption,pdflscape,subfigure,array,hyperref,booktabs,dcolumn,threeparttable, adjustbox,apacite,dirtytalk,multirow,tabularx,booktabs}
\usepackage{ulem}
\usepackage{float}
\restylefloat{table}
\begin{document}
%\begin{frame}
%\center
%\begin{centre}
\begin{table}[htbp]
%\\[-1.8ex]\hline
%\hline \\\\[-1.8ex]
%\renewcommand{\arraystretch}{1.8}
\begin{tabularx}{1\textwidth}{#{}>{\raggedright\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X#{}}
%\small
%\\[-1.8ex]
& & \multicolumn{6}{c}{Percentage Share} \\%[-1.8ex]
\cmidrule{3-8} %\\[-1.8ex]
& &A &B &C &D &E &F \\
\midrule
\multicolumn{2}{#{}l}{Mango} & 0.58 & 0.56 & 0.92 & 0.22 & 0.72 & 0.033 \\
%\tiny
\end{tabularx}
%\hline
%\hline %\\[-1.8ex]
\bigskip
\emph{Notes:} Controls Used
\caption{Mango Share}
\label{mangoshare}
\end{table}
%\end{centre}
%\end{frame}
\end{document}
In latex, I know we can use the multirow command like the following,
\begin{table}[!h]
\centering
\begin{tabular}{|c|l|}
\hline
\multirow{2}{*}{A}
& I want to place this sentence in multiple lines, \\
& but don't want to control the linebreak myself \\
\hline
\end{tabular}
\end{table}
I think it is so stupid to control the linebreak myself.
Any other alternative that fits the text width to line width?
\documentclass{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabularx}{\linewidth}{|c|X|}
\hline
A
& I want to place this sentence in multiple lines, but don't want to control the linebreak myself \\
\hline
\end{tabularx}
\end{table}
\end{document}
I would like to ask how to format table above in latex - table is pretty decent but I would like to have "model" bit right not at the very end, also I would like to have no space at the very right of the table.
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{table in stack}
\author{petr102030 Hrobar}
\date{November 2019}
\begin{document}
\maketitle
\section{Introduction}
\begin{table}[!htbp] \centering
\label{exp_rmse}
\begin{tabular}{#{\extracolsep{5pt}}lccccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
Model & \multicolumn{1}{c}{RMSE} & \multicolumn{1}{c}{MAE} & \multicolumn{1}{c}{MAPE} & \\
\hline \\[-1.8ex]
Holt-Winters (add.) & 1256.361 & 924.962 & 3.518 &\\
Holt-Winters (mul.) & 1238.799 & 909.395 & 3.457 &\\
Parab. Trend (model 4) & 2228.310 & 1792.471 & 7.959 &\\
Lin.Trend (model 5) & 3074.307 & 2545.426 & 11.339 &\\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
\end{document}
The "Model" is at the leftmost boarder of your table because the default padding is shallowed by #{\extracolsep{5pt}}. If you remove this, you'll get the padding back. (However the usual advice is to remove this padding, so please consider carefully if you really want to do this)
only specify as many columns as you have in your table and not 8 like in your example
with the siunitx package you can align the numbers nicely by their decimal markers
as already mentioned by Picaud Vincent the booktabs package is very useful to create nice looking tables. Amongst other things, it improves the vertical spacing around rules
using \label{} only makes sense if there also is a caption it can reference
I suggest to remove all the unnecessary \multicolumn{1}{...}, they don't do anything useful and can mess up the formatting
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx}
\title{table in stack}
\author{petr102030 Hrobar}
\date{November 2019}
\begin{document}
\maketitle
\section{Introduction}
\begin{table}[!htbp]
\centering
\begin{tabular}{#{}lS[table-format=4.3]S[table-format=4.3]S[table-format=2.3]}
\toprule
Model & {RMSE} & {MAE} & {MAPE} \\
\midrule
Holt-Winters (add.) & 1256.361 & 924.962 & 3.518 \\
Holt-Winters (mul.) & 1238.799 & 909.395 & 3.457 \\
Parab. Trend (model 4) & 2228.310 & 1792.471 & 7.959 \\
Lin.Trend (model 5) & 3074.307 & 2545.426 & 11.339 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
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?
I noticed some strange behaviour when combining \multirow with \multicolumn:
head 1.1 should vertically centred.
head 1.2 is supposed to be vertically and horizontally centred
Is there an alternative solution to \multirow and \multicolumn for creating more complex headers for LaTeX tables or is there a fix for my problem?
\documentclass{article}
\usepackage{multirow}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|r|r|r|r|}
\multicolumn{1}{|C{2cm}}{\multirow{3}{*}{head 1.1}} &
\multicolumn{2}{|C{2cm}}{\multirow{2}{*}{head 1.2}} &
\multicolumn{1}{|C{2cm}}{head 1.3 which is longer than expected} \\ \hline
& & & \multicolumn{1}{|C{2cm}}{head 2.3} \\
& \multicolumn{1}{|C{2cm}}{head 2.2.1} &
\multicolumn{1}{|C{2cm}}{head 2.2.2} &
\multicolumn{1}{|C{2cm}}{head 3.3}
\end{tabular}
\end{table}
\end{document}
I'd suggest stacking your multi-level headings/cells using a tabular, which will naturally centre it vertically with respect to the other cells. Such tabular stacking is made easy using makecell:
\documentclass{article}
\usepackage{makecell}
\begin{document}
\begin{tabular}{|r|r|r|r|}
head 1.1 &
\multicolumn{2}{c|}{head 1.2} &
\makecell{head 1.3 \\ which is \\ longer than \\ expected} \\
\hline
& head 2.2.1 & head 2.2.2 & \makecell{head 2.3 \\ head 3.3}
\end{tabular}
\end{document}
Other options also exist in aligning cells to the [t]op or [b]ottom.