LaTeX - two columns within the same listing? - latex

I'm trying to achieve the following but with no problems in spacing.
The image is what I'm trying to achieve but without the spacing problems :
At the moment it's just a normal listing with tabbing.
I want to avoid tabbing by introducing two columns. Is that possible?
Current code:
\begin{lstlisting}[caption=Elements of time in the background knowledge, label=btime]
year(Y):- hour(H):-
Y in 2000..2011. H in 0..23.
month(M):- minute(M):-
M in 1..12. M in 0..59.
day_of_month(D):- seconds(S):-
D in 1..31. minute(S).
date([D, M, Y]):- time([H,M]):-
year(Y), hour(H),
month(M), minute(M).
day_of_month(D).
\end{lstlisting}

Something like this (result looks like THIS)?
\begin{tabular}{p{7cm}p{7cm}}
year(Y):- & hour(H):- \\
\hspace{10mm}Y in 2000..2011. & \hspace{10mm} H in 0..23. \\
& \\
month(M):- & minute(M):- \\
\hspace{10mm} M in 1..12. & \hspace{10mm} M in 0..59. \\
& \\
day\_of\_month(D):- & seconds(S):- \\
\hspace{10mm} D in 1..31. & \hspace{10mm} minute(S). \\
& \\
date([D, M, Y]):- & \hspace{10mm} time([H,M]):- \\
\hspace{10mm} year(Y), & \hspace{15mm} hour(H), \\
\hspace{10mm} month(M), & \hspace{10mm} minute(M). \\
\hspace{10mm} day\_of\_month(D). & \\
\end{tabular}
Tweak the values p{Xcm} to get the column distance you want
Tweak the values \hspace{Xmm} to get the indentation you want
An alternative would be to use \quad or \qquad, though that might not be enough for you

Related

Is it possible to use multicolumn and multirow simultaneously in a single cell?

I'm trying to draw a table, but I faced a problem with the extra column line.
\documentclass[lettersize,journal]{IEEEtran}
\usepackage{array,tabularx}
\usepackage{pifont}
\usepackage{multirow,booktabs,tabu}
\begin{table*}[!t]
\caption{A. \label{table8}}
\centering
\begin{tabu}{|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{A} & \multicolumn{2}{c|}{\multirow{2}{*}{B}} & \multicolumn{4}{c|}{C} \\
\cline{4-7}
& & & E & F & G & H \\
\cline{1-7}
\multirow{3}{*}{D} &
\multirow{3}{*}{K} & $1.0612e-09$ & $1.0610e-09$ & $5.2760e-10$ & $3.7844e-08$ & $7.6545e-06 $\\
\cline{3-7}
& & $9.724e-10$ & $9.7239e-10$ & $4.8758e-10$ & $4.9127e-08$ & $7.7153e-06 $\\
\cline{3-7}
& & $9.132e-10$ & $9.131e-10$ & $4.1633e-10$ & $4.3932e-08$ & $8.2672e-06$\\[-1pt]
%\cline{2-7
\hline
\end{tabu}
\end{table*}
Does anyone know how to remove this extra line that shown in
Don't use the tabu package - it is more or less completely broken. The only thing which helds this package together is a lot of ducktape by the latex team.
Instead you could use tabularray package, which makes merging cells much easier and you'll also don't have to worry how long all your lines should be.
You might also want to choose another column type, like S from siunitx, to avoid the incorrect spacing around your minus signs ....
\documentclass[lettersize,journal]{IEEEtran}
\usepackage{array,tabularx}
\usepackage{pifont}
\usepackage{multirow,booktabs,tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table*}[!t]
\caption{A. \label{table8}}
\centering
\begin{tblr}{
colspec={|c|c|S[table-format=1.3e-2]|S[table-format=1.3e-2]|S[table-format=1.3e-2]|S[table-format=1.3e-2]|S[table-format=1.3e-2]|},
vlines,
hlines,
row{1-2} = {guard}
}
\SetCell[r=2]{} A & \SetCell[c=2,r=2]{} B && \SetCell[c=4]{} C &&& \\
& & & E & F & G & H \\
\SetCell[r=3]{} D &
\SetCell[r=3]{} K & 1.0612e-09 & 1.0610e-09 & 5.2760e-10 & 3.7844e-08 & 7.6545e-06\\
& & 9.724e-10 & 9.7239e-10 & 4.8758e-10 & 4.9127e-08 & 7.7153e-06\\
& & 9.132e-10 & 9.131e-10 & 4.1633e-10 & 4.3932e-08 & 8.2672e-06\\
\end{tblr}
\end{table*}
\end{document}

What Seems to be the Problem With This LaTeX Code?

I am working with Stata to create a balance table for some data using the balancetable ado package. While I believe the balancetable commands are working, the output LaTeX document won't run the table that it is trying to print. Given that I am still learning how to use LaTeX, any assistance with trying to see what the syntax issue is with this LaTeX code would be much appreciated. I'm getting issues related to the document name, typesetting and compiler issues.
\begin{tabular}{l*{3}c}
\hline\hline
& (1) & (2) & (3) \\
\hline
agesq&677.315&717.395&40.079\\
&(428.784)&(431.252)&(41.341)\\
educ&10.088&10.346&0.257\\
&(1.614)&(2.011)&(0.172)\\
black&0.827&0.843&0.016\\
&(0.379)&(0.365)&(0.036)\\
hisp&0.108&0.059&-0.048*\\
&(0.311)&(0.237)&(0.027)\\
married&0.154&0.189&0.035\\
&(0.361)&(0.393)&(0.036)\\
nodegree&0.835&0.708&-0.127***\\
&(0.372)&(0.456)&(0.039)\\
mosinex&17.862&18.492&0.630\\
&(5.574)&(4.911)&(0.511)\\
re74&2.107&2.096&-0.011\\
&(5.688)&(4.887)&(0.516)\\
re75&1.267&1.532&0.265\\
&(3.103)&(3.219)&(0.303)\\
\hline
Observations & 260 & 185 & 445 \\
\hline\hline
\end{tabular}
```!LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.1 \begin{tabular}
{l*{3}c}
?```
In LaTeX, there's some lines you should always have. \documentclass{article} (doesn't have to be the article format). Afterwards, there is the document environment where your tabular environment would be in. This would look like:
\documentclass{article}
\begin{document}
\begin{tabular}{l*{3}c}
\hline\hline
& (1) & (2) & (3) \\ \hline
agesq & 677.315 & 717.395 & 40.079 \\
& (428.784) & (431.252) & (41.341) \\
educ & 10.088 & 10.346 & 0.257 \\
& (1.614) & (2.011) & (0.172) \\
black & 0.827 & 0.843 & 0.016 \\
& (0.379) & (0.365) & (0.036) \\
hisp & 0.108 & 0.059 & -0.048* \\
& (0.311) & (0.237) & (0.027) \\
married & 0.154 & 0.189 & 0.035 \\
& (0.361) & (0.393) & (0.036) \\
nodegree& 0.835 & 0.708 & -0.127*** \\
& (0.372) & (0.456) & (0.039) \\
mosinex & 17.862 & 18.492 & 0.630 \\
& (5.574) & (4.911) & (0.511) \\
re74 & 2.107 & 2.096 & -0.011 \\
& (5.688) & (4.887) & (0.516) \\
re75 & 1.267 & 1.532 & 0.265 \\
& (3.103) & (3.219) & (0.303) \\
\hline
Observations & 260 & 185 & 445 \\
\hline\hline
\end{tabular}
\end{document}
Indentations and spacing aren't required but they do make the document more understandable for the writer. Here's what this document generates:

Table footnote of Latex table environment in r markdown

As you can see the problem in table notes in the figure below. I generated the latex code from stargazer function and manually adjusted it to meet my requirement. The table note troubled me however. how do I format the note to be the same height with the note contexts.
My latex code looks like below
\begin{table}[h] \centering
\begin{threeparttable}[b]
\caption{Regression results}
\label{results}
\begin{tabular}{#{\extracolsep{5pt}}lccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& (1) & (2) & (3) & (4) & (5) \\
\hline\\[-1.8ex]
& \multicolumn{5}{c}{A. Daily Max 8-hour Ozone Concentration} \\
\hline \\[-1.8ex]
TreatedPost & 0.034$^{***}$ & 0.006 & $-$0.063$^{***}$ & $-$0.098$^{***}$ & $-$0.105$^{***}$ \\
& 0.012 & (0.007) & (0.017) & (0.023) & (0.023) \\
& & & & & \\[-1.8ex]
\hline\\[-1.8ex]
& \multicolumn{5}{c}{B. Daily PM2.5} \\
\hline \\[-1.8ex]
TreatedPost & $-$0.245$^{***}$ & $-$0.374$^{***}$ & $-$0.505$^{***}$ & 0.203$^{***}$ & 0.230$^{**}$ \\
& 0.051 & (0.025) & (0.053) & (0.067) & (0.080) \\
& & & & & \\[-1.8ex]
\hline \\[-1.8ex]
County fixed & & Yes & Yes & Yes & Yes \\
Time fixed & & & Yes & Yes & Yes \\
County-specific trend & & & & Yes & Yes \\
Climate control & & & & & Yes \\
\hline \\[-1.8ex]
\hline \\
\end{tabular}
\begin{tablenotes}
\item[Note:] In the table, column (1)-(5) represent different models. Column (1) refers to a simple linear model; Column(2) indicates a panel data regression with county-fixed effect; Column(3) represents a panel data model with county- and time-fixed effect; Column (4) introduces county-specific time trend; Column (5) furture includes climate control variables. For panel data models, errors are clustered at county level. {$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tablenotes}
\end{threeparttable}
\end{table}

Errors in Latex I can't fix Involving Multi-Row and Mulit-Column Issues [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
\begin{center}
\footnotesize
\begin{tabular}{| c | c c c |}
\hline
\multirow{3}{*}{Equipment acquired at start of year} & \multicolumn{3}{c|}{Replacement cost (\$) for given years} & &\\
\cline{2-4}
& 1 & 2 & 3\\
\hline
1 & 4000 & \multicolumn{1}{|c|}{5400} & 9800\\
2 & 4300 & \multicolumn{1}{|c|}{6200} & 8700\\
3 & 4800 & \multicolumn{1}{|c|}{7100} & -\\
4 & 4900 & \multicolumn{1}{|c|}{-} & -\\
\hline
\end{tabular}
\end{center}
im getting an error:
Extra alignment tab has been changed to \cr.
Also for this portion of code I'm not sure what exactly is the error (I'm getting like 20 misplaced errors and missing brackets):
\begin{table}[]
\centering
\begin{tabular}{c|c|c|c|c|c|c|c|c|c|c}
\multicolumn{11}{Directed Edge Weights (Row $\rightarrow$ Col)} & & & & & & & & & & \\
\hline
$\rightarrow$ & A & B & C & D & E & F & G & H & I & J\\
\hline
A&0&4000&&&&&&&&\\
B&&0&5400&4300&&&&&&\\
C&&&0&&9800&6200&4800&&&\\
D&&&&0&9800&6200&4800&&&\\
E&&&&&0&&&8700&7100&4900\\
F&&&&&&0&&8700&7100&4900\\
G&&&&&&&0&8700&7100&4900\\
H&&&&&&&&0&&\\
I&&&&&&&&&0&\\
J&&&&&&&&&&0\\
\hline
\end{tabular}
\caption{Table of Adjacent Edges}
\label{tab:Edges of graph}
\end{table}
please help :)
In both cases it appears that there are additional cells added after your use of multicolumn. In the first case you can remove & & after the multicolumn and all should work fine:
\begin{center}
\footnotesize
\begin{tabular}{| c | c c c |}
\hline
\multirow{3}{*}{Equipment acquired at start of year} & \multicolumn{3}{c|}{Replacement cost (\$) for given years} \\
\cline{2-4}
& 1 & 2 & 3\\
\hline
1 & 4000 & \multicolumn{1}{|c|}{5400} & 9800\\
2 & 4300 & \multicolumn{1}{|c|}{6200} & 8700\\
3 & 4800 & \multicolumn{1}{|c|}{7100} & -\\
4 & 4900 & \multicolumn{1}{|c|}{-} & -\\
\hline
\end{tabular}
\end{center}
and in the second case you need to remove the repeated & symbols after multicolumn. Also in this case there is no indication of the spacing in multicolumn. The below table works fine for me, though I have added {c} in the multicolumn.
\begin{table}
\centering
\begin{tabular}{c|c|c|c|c|c|c|c|c|c|c}
\multicolumn{11}{c}{Directed Edge Weights (Row $\rightarrow$ Col)} \\
\hline
$\rightarrow$ & A & B & C & D & E & F & G & H & I & J\\
\hline
A&0&4000&&&&&&&&\\
B&&0&5400&4300&&&&&&\\
C&&&0&&9800&6200&4800&&&\\
D&&&&0&9800&6200&4800&&&\\
E&&&&&0&&&8700&7100&4900\\
F&&&&&&0&&8700&7100&4900\\
G&&&&&&&0&8700&7100&4900\\
H&&&&&&&&0&&\\
I&&&&&&&&&0&\\
J&&&&&&&&&&0\\ \hline
\end{tabular}
\caption{Table of Adjacent Edges}
\label{tab:Edges of graph}
\end{table}

LaTex: how does the include-command work?

I supposed the include-command copy-pastes code in the compilation, it is wrong because the code stopped working. Please, see the middle part in the code. I only copy-pasted the code to the file and added the include-command.
$ cat results/frames.tex
10.31 & 8.50 & 7.40 \\
10.34 & 8.53 & 7.81 \\
8.22 & 8.62 & 7.78 \\
10.16 & 8.53 & 7.44 \\
10.41 & 8.38 & 7.63 \\
10.38 & 8.57 & 8.03 \\
10.13 & 8.66 & 7.41 \\
8.50 & 8.60 & 7.15 \\
10.41 & 8.63 & 7.21 \\
8.53 & 8.53 & 7.12 \\
Latex code, see the middle part
\begin{table}
\begin{tabular}{ | l | m | r |}
\hline
$t$ / s & $d_{1}$ / s & $d_{2}$ / s \\
$\Delta h = 0,01 s$ & $\Delta d = 0,01 s$ & $\Delta d = 0,01 s$ \\
\hline
% I JUST COPIED THE CODE from here to the file, included.
% It stopped working, why?
\include{results/frames.tex}
\hline
$\pi (\frac{d_{1}}{2} - \frac{d_{2}}{2})$ & $2 \pi R h$ & $2 \pi r h$ \\
\hline
\end{tabular}
\end{table}
Use \input instead of \include, that will work.
\include additionally performs a \clearpage command which will not work in the context of a table.
Try with \input, \include is old and very limited..

Resources