LaTeX: Adding an Enumerate environment to a Tabular environment - latex

I am trying to add an ordered list (enumerate) to a table (tabular) in LaTeX with the following:
\begin{tabular}{|l|l|}
\hline
Event Flow &
\begin{enumerate}
\item This is item 1
\item This is item 2
\end{enumerate}
\\
\hline
\end{tabular}
But I am getting the following error:
! LaTeX Error: Something's
wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX
Companion for explanation. Type H
for immediate help. ...
l.34 \item T
his is item 1 ?
Can anyone please tell me what is the problem exactly?
Because when I put the enumerate environment outside of the tabular environment, it works; so guess I am currently missing something with my example of the table.

The following works:
\documentclass{article}
\begin{document}
\begin{tabular}{|l|l|}
\hline
Event Flow &
\begin{minipage}{5in}
\vskip 4pt
\begin{enumerate}
\item This is item 1
\item This is item 2
\end{enumerate}
\vskip 4pt
\end{minipage}
\\
\hline
\end{tabular}
\end{document}
I'm guessing the trouble is that the enumerate environment needs to be in vertical mode: you could experiment with a \vbox.

You could use the following solution:
\documentclass{article}
\begin{document}
\begin{tabular}{|l|p{5cm}|}
\hline
Event Flow &
\begin{enumerate}
\item This is item 1
\item This is item 2
\end{enumerate} \\
\hline
\end{tabular}
\end{document}
In other words, you can avoid the need for a minipage by simply creating a paragraph type column (which has a specified width). This compiles to

Related

How to decrease header level in Overleaf for table of figures + tables?

I'm trying to figure out how to change my list of figures and tables so it refers to figures and tables on a section level. My document type is article in overleaf.
My current code looks as follows:
\documentclass{article}
\begin{document}
\maketitle
\section{Abstract}
\newpage
\tableofcontents
\newpage
\addcontentsline{toc}{section}{\listfigurename}
\listoffigures
\newpage
\addcontentsline{toc}{section}{\listtablename}
\listoftables
\newpage
\section{Introduction}
\section{3}
\section{4}
\begin{table}[H]
\renewcommand{\arraystretch}{2}
\centering
\begin{tabular}{ p{6cm}p{6cm}}
\toprule
\textbf{Variables} & \textbf{Description} \\ \midrule
\textit{F\_27608, R\_27730} & The amount of cheese and yogurt ordered weekly. \\
\textit{Year} & Year of the observation. \\
\textit{Winter, Spring, Summer, Autumn} & Season of the observation. \\
\textit{Week} & Week of the observation. \\
\textit{Lag1, Lag2, Lag3, Lag4, Lag5} & Lagged order amounts for prior periods. \\
\textit{Price} & Mean price of the product for the specific observation. \\
\textit{Fut1, Fut2, Fut3, Fut4, Fut5} & Future price of the product. \\
\textit{PromoScale} & Level of expected increase in orders caused by promotion. \\
\textit{PromoScale(L1, L2, L3)} & Lagged PromoScale values for prior periods \\
\textit{PromoScale(F1, F2, F3)} & Future PromosSale values. \\ \bottomrule
\end{tabular}
\caption{Feature space cheese and yogurt}
\end{table}
See picture:
List of tables
How do i make it so that these tables say 4.1 and 4.2 in the list of tables? (the code only shows one table for reference)
You can use \counterwithin{figure}{section} to number a counter within a section:
\documentclass{article}
\counterwithin{figure}{section}
\counterwithin{table}{section}
\begin{document}
\section{Abstract}
\newpage
\tableofcontents
\newpage
\addcontentsline{toc}{section}{\listfigurename}
\listoffigures
\newpage
\addcontentsline{toc}{section}{\listtablename}
\listoftables
\newpage
\section{Introduction}
\section{3}
\section{4}
\begin{table}[htbp]
\caption{Feature space cheese and yogurt}
\end{table}
\end{document}

Missing control sequence inserted. \end{tabulary} error in revtex4-2 template aps

I am writing a paper in APS journal template : revtex4-2, when I import my table I have this error :
Missing control sequence inserted. \end{tabulary}. But this table has no problem in other template for example IEEE. I dont know how fix it. I really appreciate any help.
\documentclass[aps,pra,twocolumn,floatfix,footinbib,notitlepage,superscriptaddress,groupaddress,showpacs]{revtex4-2}
\usepackage{graphicx,graphics,times,bm,bbm,bbold,amssymb,amsmath,amsfonts,dsfont,hyperref,mathrsfs,color,caption,subcaption,cancel}
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}
\begin{document}
\preprint{AIP/123-QED}
%\title[Sample title]{Sample Title:\\with Forced Linebreak\footnote{Error!}}% Force line breaks with \\
\title[]
\author{}
\affiliation{}
\author{}
\affiliation{}
\email{}
\date{\today}
\begin{abstract}
\end{abstract}
% \keywords{}
% \maketitle
\section{Introduction}\label{sec:introduction}
\section{Theoretical Analysis}
\begin{table}[h!]
\centering
\caption{List of Parameters Values }
\label{table:1}
\begin{adjustbox}{max width=8.5 cm}
\begin{tabulary}{\columnwidth}{#{}llr#{}}
\toprule
\textbf{Parameters} & \textbf{Values} & \textbf{Units}\\
\midrule
$\lambda$ & 1550 & $nm$ \\
\bottomrule
\end{tabulary}
\end{adjustbox}
\end{table}.
\end{document}
%
% ****** End of file aipsamp.tex ******
I suggest the new and much more flexible tabularray package instead.
Also don't scale content which contains text, this will result in an suboptimal result. If in your real document, you must make the table smaller, use a smaller font size instead of scaling it with adjustbox.
(you should really clean up your preamble and remove duplicates and outdated packages)
\documentclass[aps,pra,twocolumn,floatfix,footinbib,notitlepage,superscriptaddress,groupaddress,showpacs]{revtex4-2}
\usepackage{graphicx,graphics,times,bm,bbm,bbold,amssymb,amsmath,amsfonts,dsfont,hyperref,mathrsfs,color,caption,subcaption,cancel}
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\preprint{AIP/123-QED}
%\title[Sample title]{Sample Title:\\with Forced Linebreak\footnote{Error!}}% Force line breaks with \\
\title[]
\author{}
\affiliation{}
\author{}
\affiliation{}
\email{}
\date{\today}
\begin{abstract}
\end{abstract}
% \keywords{}
% \maketitle
\section{Introduction}\label{sec:introduction}
\section{Theoretical Analysis}
\begin{table}[h!]
\centering
\caption{List of Parameters Values }
\label{table:1}
% \begin{adjustbox}{max width=8.5 cm}
\begin{tblr}{width=0.8\linewidth,colspec={#{}X[l]X[l]X[r]#{}}}
\toprule
\textbf{Parameters} & \textbf{Values} & \textbf{Units}\\
\midrule
$\lambda$ & 1550 & $nm$ \\
\bottomrule
\end{tblr}
% \end{adjustbox}
\end{table}
\end{document}
%
% ****** End of file aipsamp.tex ******

error using \hline in LaTeX not interrupting compiling but maybe I am doing this the wrong way

So I'm using \hline to create some underlines for the heading of a \section{} but I'm getting the error
Misplaced \noalign.
You have used a \hline command in the wrong place, probably outside a table. If the \hline command is written inside a table, try including \\ before it.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \#height \arrayrulewidth \futurelet...
l.15 \hline
I expect to see \noalign only after the \cr of
an alignment. Proceed, and I'll ignore this case.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[dvipsnames]{xcolor}
\setlength{\emergencystretch}{10pt}
\title{Law and Society Notes}
\author{Jack Dwyer }
\date{}
\begin{document}
\maketitle
\section{January 31}
\hline
\begin{itemize}
\item[] \hline
\item Types of law
\begin{itemize}
\item Oral Nomoi
\item Thesmoi
\item Written Nomoi
\item Psephismata
\end{itemize}{}
\item Distinctions not drawn between criminal and civil cases or judicial, legislative, or administrative cases
\item Types of cases
\begin{itemize}
\item Dikē(Public)
\item Graphē(semi-public)
\end{itemize}{}
\item Sycophant – suck up
\item Righteous Indignation
\end{itemize}{}
\hline is for the use inside tabulars. You could use \hrulefill or, better, don't manually underline the section but format it appropriatly, e.g. https://tex.stackexchange.com/a/453372
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[dvipsnames]{xcolor}
\setlength{\emergencystretch}{10pt}
\title{Law and Society Notes}
\author{Jack Dwyer }
\date{}
\begin{document}
\maketitle
\section{January 31}
\hrulefill
\begin{itemize}
\item[] \hrulefill
\item Types of law
\begin{itemize}
\item Oral Nomoi
\item Thesmoi
\item Written Nomoi
\item Psephismata
\end{itemize}
\item Distinctions not drawn between criminal and civil cases or judicial, legislative, or administrative cases
\item Types of cases
\begin{itemize}
\item Dikē(Public)
\item Graphē(semi-public)
\end{itemize}
\item Sycophant – suck up
\item Righteous Indignation
\end{itemize}
\end{document}

\table in \enumerate environment in latex

I want to insert a \table in \enumerate environment and I have something like this:
\begin{enumerate}
\item Item 1.
\item Item 2.
\item \begin{table}[htbp]
\textbf{\caption{Table1 Caption}}
\centering
\begin{tabular}{c c}
\hline\hline
Value 1 & Value 2\\
\hline
r1c1 & r2c2\\
r2c1 & r2c2\\
r3c1 & r3c2\\
\hline
\end{tabular}
\label{table1}
\end{table}
\item \begin{table}[htbp]
\textbf{\caption{Table 2 Caption}}
\centering
\begin{tabular}{ccc}
\hline\hline
Value 1 & Value 2 & Value 3\\
\hline
r1c1 & r1c2 & r1c3\\
r2c1 & r2c2 & r2c3\\
r3c1 & r3c2 & r3c3\\
\end{tabular}
\label{table2}
\end{table}
\item \ref{table1} and \ref{table2}
\end{enumerate}
But when I compile the latex document the \enumerate number are no where near the table. Also when I refer to label "table1" and "table2" it shows up as 3 and 4 respectively (for extra info this part is in subsection 3.3 and these are the only two tables in the whole document).
How do I use \table environment with \enumerate environment. I have seen people use just \tabular with \enumerate but I want to use \table as it gives me an easy option to define \caption and \label.
Also regarding table labeling I am assuming it has something to do with subsection number but I can't really figure it out.
I would really appreciate any help regarding this matter.
A table environment is a float. It is not meant to be included in other environments.
You can use a tabular environment like this:
\documentclass[a4paper, 11pt]{article}
\begin{document}
\begin{enumerate}
\item Item 1.
\item Item 2.
\item \begin{tabular}[t]{c c}
Value 1 & Value 2\\
\hline
r1c1 & r2c2\\
r2c1 & r2c2\\
r3c1 & r3c2\\
\hline
\end{tabular}
\item \begin{tabular}[t]{ccc}
Value 1 & Value 2 & Value 3\\
\hline
r1c1 & r1c2 & r1c3\\
r2c1 & r2c2 & r2c3\\
r3c1 & r3c2 & r3c3\\
\end{tabular}
\end{enumerate}
\end{document}
The output will look like this:
Note that the vertical alignment will look weird if you try tp put \hline on top of the table.
Edit 1: You can put a \label almost everywhere you like, but it will not refer to itself as a "Table" unless a variable is set. You'd have to delve into the bowels of LaTeX to see how that is done.
There are at least two packages (capt-of and caption) that provide a \captionof command to define a caption outside a figure or table environment.

Comments in LaTeX break pandoc table

Pandoc is unable to convert LaTeX tables with an "% END" comment:
\documentclass{article}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|l|l|l|}
a & a & a \\
a & a & a \\
a & a & a \\
% END
\end{tabular}
\caption{example}
\label{tab:example}
\end{table}
\end{document}
The same example without the comment works fine.

Resources