Table reference not working properly when using \setcounter{table}{0} in appendix in latex - latex

I am trying to fix an issue with my latex document, and need help.
I am using \documentclass[12pt]{article} environment in Latex. The issue is the following:
I have added an appendix using
\appendix
\section{Appendix}\label{appendix_a}
and used
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
to generate table names as Table A1 and so on.
However, when I use \setcounter to restart the table numbering, my labels stop working. But if I remove the \setcounter command, my labels work perfectly, but then the table number continue from where I left before appendix, that is Table A6 and not Table A1.
Here is my minimum working example:
\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}
\section{Section A}
Table \ref{tab_main} is the first table.
\begin{table}
\centering
\input{Main_Table}
\caption{Main Table}
\label{tab_main}
\end{table}
See table \ref{tab_appendix} in the appendix.
\appendix
\section{Appendix}\label{appendix_a}
%\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
\begin{table}
\input{Appendix_Table}
\caption{Appendix Table}
\label{tab_appendix}
\end{table}
\end{document}
And here are tables that I have used:
Main_Table.tex
\begin{centre}
\begin{table}[H]
\\[-1.8ex]\hline
\hline \\[-1.8ex]
\begin{tabularx}{1\textwidth}{>{\raggedright\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X}
\small
& & \multicolumn{3}{c}{Heading} \\
\midrule
\multicolumn{2}{l}{Koo} & 1 & 2 & 3 \\
\multicolumn{2}{l}{Koo} & 1 & 2 & 3 \\
\midrule
\multicolumn{2}{l}{Koo} & A & B & C \\
\multicolumn{2}{l}{Koo} & A & B & C \\
\multicolumn{2}{l}{Koo} & A & B & C \\
\multicolumn{2}{l}{Koo} & A & B & C \\
\tiny
\end{tabularx}
\hline
\hline \\[-1.8ex]
\smallskip
\multicolumn{5}{l}{\parbox[t]{\textwidth}{\footnotesize{\emph{Notes}: Main}}}
\end{table}
\end{centre}
Appendix_Table.tex
\begin{centre}
\begin{table}[H]
\\[-1.8ex]\hline
\hline \\[-1.8ex]
\begin{tabularx}{1\textwidth}{>{\raggedright\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X}
\small
& & \multicolumn{3}{c}{Heading} \\
\midrule
\multicolumn{2}{l}{Foo} & 1 & 2 & 3 \\
\multicolumn{2}{l}{Foo} & 1 & 2 & 3 \\
\midrule
\multicolumn{2}{l}{Foo} & A & B & C \\
\multicolumn{2}{l}{Foo} & A & B & C \\
\multicolumn{2}{l}{Foo} & A & B & C \\
\multicolumn{2}{l}{Foo} & A & B & C \\
\tiny
\end{tabularx}
\hline
\hline \\[-1.8ex]
\smallskip
\multicolumn{5}{l}{\parbox[t]{\textwidth}{\footnotesize{\emph{Notes}: Appendix}}}
\end{table}
\end{centre}
Any help on this front would be appreciated.
Thank You

\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}
\usepackage{appendix}
\begin{document}
\section{Section A}
Table \ref{tab_main} is the first table.
\begin{table}[htbp]
\centering
main table
\caption{Main Table}
\label{tab_main}
\end{table}
See table \ref{tab_appendix} in the appendix.
\appendix
\section{Appendix}\label{appendix_a}
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
\renewcommand*{\theHtable}{\thetable}
\begin{table}[htbp]
\centering
appendix table
\caption{Appendix Table}
\label{tab_appendix}
\end{table}
\end{document}

Related

Latex table alignment problem with multicolumn and multirow

How can I align this table. It does not algin column two and three at center.
I am using following code:
\begin{table}[htbp]
\caption{Comparison with the hybrid architecture}
\label{tab:comparison}
\begin{center}
\begin{tabular}{|l|c|c|}
\hline
\multicolumn{1}{|c|}{} & \multicolumn{2}{c|}{\textit{Average Episode Reward for 10 Runs (deviation)}} \\ \cline{2-3}
\multicolumn{1}{|c|}{} & \multicolumn{2}{c|}{\textit{Disturbance Magnitude}} \\
\cline{2-3}
\multicolumn{1}{|c|}{\multirow{-3}{*}{\textit{Architecture}}}
& 65\% & 70\% \\ \hline
PID & -17.71 & -23.54 \\
CoL-DRL & -2.58 & -12.25 \\
\rowcolor[HTML]{9AFF99} CoL-DRPRL & -1.85 & -6.25 \\ \hline
\end{tabular}
\end{center}
\end{table}

Overleaf Appendix Table Numbering

I am using overleaf to write a journal article and want to move a lot of my results table to the Appendix. So I write the following commands:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{outlines}
\usepackage{dirtytalk}
\usepackage{latexsym}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{booktabs,caption}
\usepackage{longtable}
\usepackage{appendix}
\usepackage[para,online,flushleft]{threeparttable}
\usepackage[affil-it]{authblk}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\renewcommand{\baselinestretch}{1.5}
\begin{document}
\bibliographystyle{IEEEtran}
\bibliography{bibliography.bib}
\appendix
\section{Tables}
\begin{table}[!]
\begin{scriptsize}
\centering
\caption{Reduced Form Estimates using Linear Probability Model}
\label{tab:my-table}
\begin{tabular}{#{}lcccc#{}}
\hline
\hline
& (1) & (2) & (3) & (4) \\
VARIABLES & A & B & C & D \\
\hline
&&&& \\
&&&& \\
&&&& \\
\hline
\multicolumn{5}{c}{\textit{Note:}Robust standard errors in parentheses *** p$<$0.01, ** p$<$0.05, * p$<$0.1 }
\end{tabular}
\end{scriptsize}
\end{table}
\end{document}
While the section is recognized as appendix and tables, the numbering of the tables continue from the main text. How do I go from for example: Table 12 to Table A1?
Thanks
You could use
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
to change the numbering style of the appendix tables
Please also note that scriptsize is NOT an environment, it is a macro.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{outlines}
\usepackage{dirtytalk}
\usepackage{latexsym}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{booktabs,caption}
\usepackage{longtable}
\usepackage{appendix}
\usepackage[para,online,flushleft]{threeparttable}
\usepackage[affil-it]{authblk}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\renewcommand{\baselinestretch}{1.5}
\begin{document}
\bibliographystyle{IEEEtran}
\bibliography{bibliography.bib}
\begin{table}[htbp]
%\begin{scriptsize}
\scriptsize
\centering
\caption{Reduced Form Estimates using Linear Probability Model}
\label{tab:my-table-}
\begin{tabular}{#{}lcccc#{}}
\hline
\hline
& (1) & (2) & (3) & (4) \\
VARIABLES & A & B & C & D \\
\hline
&&&& \\
&&&& \\
&&&& \\
\hline
\multicolumn{5}{c}{\textit{Note:}Robust standard errors in parentheses *** p$<$0.01, ** p$<$0.05, * p$<$0.1 }
\end{tabular}
%\end{scriptsize}
\end{table}
\appendix
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}
\section{Tables}
\begin{table}[htbp]
%\begin{scriptsize}
\scriptsize
\centering
\caption{Reduced Form Estimates using Linear Probability Model}
\label{tab:my-table}
\begin{tabular}{#{}lcccc#{}}
\hline
\hline
& (1) & (2) & (3) & (4) \\
VARIABLES & A & B & C & D \\
\hline
&&&& \\
&&&& \\
&&&& \\
\hline
\multicolumn{5}{c}{\textit{Note:}Robust standard errors in parentheses *** p$<$0.01, ** p$<$0.05, * p$<$0.1 }
\end{tabular}
%\end{scriptsize}
\end{table}
\end{document}

How to create a multirow multicolumn table with subheadings below the first row

I am attempting to create a table in latex as below, although I am a bit confused about where and when the \multirow and \multicolumn commands are to be used inside a tabular environment. Col_1, Col_2, and Col_3 are supposed to be subheadings but they need to appear in the second row.
What I started off with is, (the columns are duplicated, so I wanted to split it into multiple rows as shown in the image) :
\begin{table}[H]
\begin{tabular}{lSSSSSSSS}
\toprule
\multirow{2}{*}{\textbf{A}} &
\multicolumn{3}{c}{\textbf{Model_1}} &
\multicolumn{5}{c}{\textbf{Model_2}} \\
& {Col_1} & {Col_2} & {Col_3} & {Col_1} & {Col_2} & {Col_3} & {Col_4} & {Col_5} \\
\midrule
x\% & a\% b\% & c\% & x\% & y\% & z\% & 0. & 0. \\
\bottomrule
\end{tabular}
\caption{results}
\end{table}
You can place your subheaders in a row of their own, no need to worry about mutirows and such
\documentclass{article}
\usepackage{siunitx}
%\usepackage{booktabs}
\usepackage{float}
\begin{document}
\begin{table}[H]
\begin{tabular}{l|S|S|S}
\textbf{A} & \multicolumn{3}{c}{x\%} \\
\hline
& {Col\_1} & {Col\_2} & {Col\_3} \\
Model\_1 & a\% & b\% & c\% \\
\hline
Model\_2 & x\% & y\% & z\% \\
\end{tabular}
\caption{results}
\end{table}
\end{document}
Instead of the layout you show in your image, I rather suggest to avoid vertical lines for a more professional looking result:
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{#{}lSSSSSSSS#{}}
\toprule
\textbf{A} &
\multicolumn{3}{c}{\textbf{Model\_1}} &
\multicolumn{5}{c}{\textbf{Model\_2}} \\
& {Col\_1} & {Col\_2} & {Col\_3} & {Col\_1} & {Col\_2} & {Col\_3} & {Col\_4} & {Col\_5} \\
\cmidrule(r){2-4}\cmidrule(l){5-9}
x\% & a\% & b\% & c\% & x\% & y\% & z\% & 0. & 0. \\
\bottomrule
\end{tabular}
\caption{results}
\end{table}
\end{document}

How to vertically center my latex table cell

My Latex tabular looks like this
\begin{table}
\centering
\begin{tabular}{clll}
\toprule
\multirow{2}*{Name} & \multirow{2}*{Description} & \multicolumn{2}{c}
{Time} \\
\cline{3-4}
& & Item1 & Item2 \\
\midrule
App1 & Good & 1000ms & 1000ms \\
\bottomrule
\end{tabular}
\end{table}
'
I wonder how can I make Item1 and Item2 in the above table vertically-centered. Thank you!
You can use the command \cmidrule{3-4}: it is equivalent to \cline{3-4}, but it improves the looking of the table.
\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
\begin{table}
\begin{center}
\begin{tabular}{clll}
\toprule
\multirow{2}*{Name} & \multirow{2}*{Description} & \multicolumn{2}{c} {Time} \\
\cmidrule{3-4}
& & Item1 & Item2 \\
\midrule
App1 & Good & 1000ms & 1000ms \\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}

Latex table multiple row and multiple column

I'm trying to create a table in Latex but without success. I tried different solutions but no one solves my problem.
I would like create a table like the picture below:
Can anyone show how to do this in Latex please?
One first sketch may be the following:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{A} & \multicolumn{2}{c|}{User B} & %
\multicolumn{2}{c|}{User C} & \multirow{3}{*}{D}\\
\cline{2-5}
& \multicolumn{2}{c|}{Value} & \multicolumn{2}{c|}{Value} & \\
\cline{2-5}
& B1 & B2 & C1 & C2 & \\
\hline
& & & & & \\
\hline
& & & & & \\
\hline
% etc. ...
\end{tabular}
\end{document}
It produces:
Addendum:
\documentclass{article}
\usepackage{multirow}
\begin{document}
{\sffamily %
\begin{tabular}{|c|c|c|c|c|c|c|}% seven columns now, not six...
\hline
\multirow{3}{*}{A} & \multicolumn{2}{c|}{User B} & \multirow{3}{*}{X} & %
\multicolumn{2}{c|}{User C} & \multirow{3}{*}{D}\\
\cline{2-3}\cline{5-6}
& \multicolumn{2}{c|}{Value} & & \multicolumn{2}{c|}{Value} & \\
\cline{2-3}\cline{5-6}
& B1 & B2 & & C1 & C2 & \\
\hline
& & & & & & \\
\hline
& & & & & & \\
\hline
% etc. ...
\end{tabular}
}%
\end{document}
produces:
Please, critically check all the differences between the original code and this latter.
Don't forget that several LaTeX packages can help you improving style, dimensions and spacing of your table: among these, I advise you to have a look at bigstrut.
Also:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{A} & \multirow{3}{*}{X} & \multicolumn{2}{c|}{User B} & \multicolumn{2}{c|}{User C} & \multirow{3}{*}{D}\\
\cline{3-6}
& & \multicolumn{2}{c|}{Value} & \multicolumn{2}{c|}{Value} & \\
\cline{3-6}
& & B1 & B2 & C1 & C2 & \\
\hline
& & & & & & \\
\hline
\end{tabular}
\end{document}
You should now be able to operate on your own further changes to the model of table.
Check out the multirow package:
http://texblog.org/2012/12/21/multi-column-and-multi-row-cells-in-latex-tables/
You have to include the library:
%multi-column
\multicolumn{number cols}{align}{text} % align: l,c,r
%multi-row
\usepackage{multirow}
\multirow{number rows}{width}{text}
Then it looks like this:
\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}
\begin{table}[ht]
\caption{Multi-column and multi-row table}
\begin{center}
\begin{tabular}{ccc}
\hline
\multicolumn{2}{c}{\multirow{2}{*}{Multi-col-row}}&X\\
\multicolumn{2}{c}{}&X\\
\hline
X&X&X\\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}
note: code examples from the link provided

Resources