2

I have a following problem. I would like to put my table exactly below the name of the section and subsection.

See my code bellow:

\section{Robustness checks}
\label{rob_check}
\subsection{Maximum daily temperature}
\label{maximalka}
\begin{sidewaystable}[p]
    \label{HomTmax}
    \caption{Homicides per 1,000,000 people - Poisson regression. Maximum daily temperature.}
    \begin{tabular}{l c c c c c c c c}
        \toprule
        \textbf{Variable} & \textbf{(1)}  & \textbf{(2)} & \textbf{(3)} & \textbf{(4)}  & \textbf{(5)}  & \textbf{(6)}  & \textbf{(7)}  & \textbf{(8)}\\ 
        \midrule
        $Temperature$   & -0.0008 & -0.018 &   &-0.0002 &  -0.01    & -0.026**& & -0.009 \\
                         & (0.007)& (0.01) &   & (0.007)&  (0.007)  & (0.012)& & (0.007)\\
    \end{tabular}
\end{sidewaystable}

But I got this output, where the table is on the new page: enter image description here

I tried to follow advice here Put tables under subsections (using \clearpage) but it did not work to me. Can you help me, please?

EDIT: I really need table in the landscape format. If I use \small, I got overlapping numbers, see this result: enter image description here

vojtam
  • 169
  • 6
    A sidewaystable is always placed on a separate page, see https://tex.stackexchange.com/questions/69286/rotate-table-with-caption-on-the-same-page for some options for having a rotated table on the same page as other text. Note also that if you use just [p] as the float specifier for a normal float, that means it always ends up on a page of it's own, because that's the only option you've allowed for. – Torbjørn T. May 08 '21 at 07:34
  • thanks for your reply. Is there another way, how can I placed my rotated table bellow the name of the subsection? I tried \rotatebox{90}{% \begin{varwidth}{\textheight} but I got and error You can't use ``\vadjust' in internal vertical mode. \end{varwidth}{varwidth}} – vojtam May 08 '21 at 07:45
  • 1
    Do you really need to rotate the table? With a slightly smaller font size and adjusted values of \tabcolsep, your table probably fits into the textwidth even in portrait orientation. This is however hard to tell, since the textwidth is currently unknown. – leandriis May 08 '21 at 07:51
  • 2
    Don't know why you got that error, I suggest you edit your question with a complete example og the new code you tried. – Torbjørn T. May 08 '21 at 07:52
  • 1
    Entirely unrelated, but please keep in mind to place the \label after the corresponding \caption. – leandriis May 08 '21 at 07:54
  • Please make your code compilable by adding the documentclass as well as the relevant packages. Did you alter the margins (e.g.through the geometry package)? If so, include the correpsonding settings, as well. (See also: minimal working example (MWE)) While it is indeed a good idea to just include a part of a table in order to keep the example code concise, please make sure, that the code represents the contents of the actual table. What kind of contents do the columns "(3)" and "(7)" actually contain? How wide is the widest entry of each column? – leandriis May 08 '21 at 08:19
  • 1
    The code you posted does not match the updated output you get. In the code, there are no asterisks, exept for the entry in column (5), in the screenshot, almost all numbers are accompanied with asterisks. Since they also take up space solutions based on the code you posted will most likely not result in a satisfactory output if you change the numbers/ add asterisks. If you want a more specific advice, tailored to your table, update your question according to my previous comment. – leandriis May 08 '21 at 09:09

3 Answers3

4

As @leandriis as noted in a comment, it doesn't seem to be necessary to typeset the tabular material in landscape format. A combination of switching to \small and using a tabular* environment appears to do the job just fine. If there's anything I'd really recommend changing about the table, it's to set it up so that the numbers in the 8 data columns are aligned on their decimal markers. This may be achieved in several ways; one of is with the use of the machinery of the dcolumn package.

enter image description here

\documentclass{article}

\usepackage{booktabs} \usepackage{dcolumn} % for 'D' column type \newcolumntype{d}[1]{D..{#1}} \newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\section{Robustness checks} \label{rob_check}

\subsection{Maximum daily temperature} \label{maximalka}

\begin{table}[h!] \setlength\tabcolsep{0pt} \small \caption{Homicides per 1,000,000 people --- Poisson regression. Maximum daily temperature.} \label{HomTmax} \smallskip \begin{tabular}{\textwidth}{@{\extracolsep{\fill}} l {8}{d{2.4}} } \toprule \textbf{Variable} & \mc{\textbf{(1)}} & \mc{\textbf{(2)}} & \mc{\textbf{(3)}} & \mc{\textbf{(4)}}
& \mc{\textbf{(5)}} & \mc{\textbf{(6)}} & \mc{\textbf{(7)}} & \mc{\textbf{(8)}}\ \midrule Temp. & -0.0008 & -0.018 & &-0.0002 & -0.01 & -0.026*& & -0.009 \ & (0.007) & (0.01) & & (0.007)& (0.007) & (0.012) & & (0.007) \ \bottomrule \end{tabular} \end{table}

\end{document}

Mico
  • 506,678
  • Thanks for your reply, but I really need table in a landscape format. See my edit – vojtam May 08 '21 at 08:45
  • @vojtam - Actually, you do not need landscape mode. You just need to adjust the column definitions to afford them more space. E.g., if there's a chance that three asterisks will accompany numbers in the first data column, change *{8}{d{2.4}} to d{2.7} *{7}{d{2.4}}. If all 8 data columns can contain triple asterisks, you could switch from \small to \footnotesize and from *{8}{d{2.4}} to *{8}{d{2.7}}, – Mico May 08 '21 at 09:07
4

Here is my attempt. Since there was unfortunately no information about the preamble, especially about the documentclass, in the question, I had to guess. Based on the sans serif font in the headings in combination with a serif font in the actual table, I assume, you used one of the KOMA script classes. For my MWE, I opted for the scrartcl class.

As mentioned in a previous comment, I don't really see the need to rotate the table, given the information you provide so far. If you get a different output, and you can't seem to fit the table into the avialable space, please update your question as described in my previous comment.

In my MWE, I included two versions of your table, a rotated one and one that isn't rotated. In both version, I used the siunitx package in order to improve the alignment of the numbers in your table. Depending on the entries in all the other table rows, you might have to adjust the values of table-format accordingly. (Red lines in the following screenshot indicate the margins.)

enter image description here

\documentclass{scrartcl}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{caption}

\usepackage{siunitx} \sisetup{ group-digits = true, group-minimum-digits = 4, group-separator = {,}, table-align-text-pre = false, table-align-text-post = false, input-open-uncertainty = , input-close-uncertainty = , table-space-text-pre = {(}, }

\begin{document}

\section{Robustness checks} \label{rob_check} \subsection{Maximum daily temperature} \label{maximalka} \begin{center} \begin{sideways} \begin{minipage}{1.3\textwidth} \captionof{table}{Homicides per \num{1000000} people - Poisson regression. Maximum daily temperature.} \label{HomTmax} \centering \sisetup{group-digits=false} \begin{tabular}{@{}l S[table-format=-1.5] S[table-format=-1.3] c S[table-format=-1.4] S[table-format=-1.3, table-space-text-post={)}] S[table-format=-1.3, table-space-text-post={**}] c S[table-format=-1.3, table-space-text-post={)}]@{}} \toprule \textbf{Variable} & \textbf{(1)} & \textbf{(2)} & \textbf{(3)} & \textbf{(4)} & \textbf{(5)} & \textbf{(6)} & \textbf{(7)} & \textbf{(8)}\ \midrule Temperature & -0.0008 & -0.018 & &-0.0002 & -0.01 & -0.026**& & -0.009 \ & (0.007)& (0.01) & & (0.007)& (0.007) & (0.012)& & (0.007)\ \end{tabular} \end{minipage} \end{sideways} \end{center} \clearpage

\section{Robustness checks} \label{rob_check} \subsection{Maximum daily temperature} \label{maximalka} \begin{table}[hbp] \caption{Homicides per \num{1000000} people - Poisson regression. Maximum daily temperature.}\label{HomTmax} \centering \small \sisetup{group-digits=false} \begin{tabular}{@{}l S[table-format=-1.4] S[table-format=-1.3] c S[table-format=-1.4] S[table-format=-1.3, table-space-text-post={)}] S[table-format=-1.3, table-space-text-post={**}] c S[table-format=-1.3, table-space-text-post={)}]@{}} \toprule \textbf{Variable} & {\textbf{(1)}} & {\textbf{(2)}} & {\textbf{(3)}} & {\textbf{(4)}} & {\textbf{(5)}} & {\textbf{(6)}} & {\textbf{(7)}} & {\textbf{(8)}}\ \midrule Temperature & -0.0008 & -0.018 & &-0.0002 & -0.01 & -0.026**& & -0.009 \ & (0.007)& (0.01) & & (0.007)& (0.007) & (0.012)& & (0.007)\ \end{tabular} \end{table}

\end{document}

leandriis
  • 62,593
3
  • from information, which you provide is no evidence, that table shoud be in landscape orientation.
  • by using siunitx, tabularx and threeparttable assuming that \textwidth is sufficient big (about 20% bigger aa is default size at article) , with use of the \small font you can write your table on the following way:
\documentclass{article}
\usepackage{geometry} % < --- assumed
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage[skip=1ex, font=small, labelfont=bf]{caption} \usepackage{siunitx} %\usepackage[referable]{threeparttablex} \usepackage{booktabs,tabularx, threeparttable} \newcolumntype{C}{>{\centering\arraybackslash}X} \newcommand\mcxbf[1]{\multicolumn{1}{C}{\textbf{#1}}}

\begin{document} \section{Robustness checks} \label{rob_check} \subsection{Maximum daily temperature} \label{maximalka}

\begin{table}[ht]

\begin{threeparttable} \caption{Homicides per 1,000,000 people - Poisson regression. Maximum daily temperature.} \label{HomTmax} \sisetup{table-space-text-pre={(}, table-align-text-pre=false, table-space-text-post={$^{*}$}, table-align-text-post=false, input-open-uncertainty = , input-close-uncertainty = , table-format=-1.3 } \setlength\tabcolsep{3pt} \small \begin{tabularx}{\linewidth}{@{} l *{8}{S} @{}} \toprule \textbf{Variable} & \mcxbf{(1)} & \mcxbf{(2)} & \mcxbf{(3)} & \mcxbf{(4)} & \mcxbf{(5)} & \mcxbf{(6)} & \mcxbf{(7)} & \mcxbf{(8)} \ \midrule \textit{Temperature} & -0.0008 & -0.018 & & -0.0002 & -0.01 & -0.026 & & -0.009\tnote{} \ & (0.007) & (0.01) & & (0.007) & (0.007) & (0.012) & & (0.007) \ \addlinespace \textit{Something} & -0.0008 & -0.018 & & -0.0002 & -0.01 & -0.026\tnote{} & & -0.009 \ & (0.007) & (0.01) & & (0.007) & (0.007) & (0.012) & & (0.007) \ \bottomrule \end{tabularx} \footnotesize \begin{tablenotes}[flushleft, para]\footnotesize \item[] $p<$0.1; \item[**] $p<0.05$; \item[***] $p<0.01$ \end{tablenotes} \end{threeparttable} \end{table} \end{document}

enter image description here

(red lines indicate part of page layout)

Zarko
  • 296,517