2

I have to produce two different versions of a document: one with author-year citations, and one with numbered citations. Thus, I'm using natbib and for each document I modify the natbib options.

Although I can provide a width for the table's citation column, I would like it to automatically decide the width as with numbered citations its width is much smaller than needed with a author-year citation. How can I go about solving this issue (preferably automatically)?

tableinmargin

The following is the MWE that generates this:

\begin{filecontents*}{database.bib}
@article{Somecite,
    author = {First Last and Fname Lname and F.N. Somename},
    title = {Title of this wonderful article},
    journal = {Unknown journal},
    volume = {2},
    number = {5},
    pages = {100--101},
    year = {1901}
}
@misc{Anothercite,
    author = {{Company Has A Terrible Long Abbreviation (CHATLA)}},
    title = {CHATLNAA does everything for you},
    howpublished = {\url{http://www.chatlnaa.com}},
    year = {2017},
    note = {Accessed today}
}
\end{filecontents*}

\documentclass[a4paper]{report}
\usepackage[authoryear,round,semicolon,sort]{natbib}
%\usepackage[numbers,square,comma,sort]{natbib}
\usepackage{longtable}
\usepackage{rotating}

\newcommand{\bs}{\begin{sideways}}
\newcommand{\es}{\end{sideways}}

\begin{document}

Here is some text, and we refer to \citep{Somecite}. \Citet{Anothercite} is there too. See table.

\scriptsize
\begin{longtable}{|p{2.2cm}cp{2cm}c|p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}p{0.15cm}|}
    \caption{Overview of a table with a lot of numbers.}\label{tbl:numbers} \\
    \hline
    Name &  &Location   &Number 1   & \multicolumn{7}{c|}{Items} \\
                        &   &                   &               &\bs Item 1 \es &\bs Item 2 \es &\bs Item 3 \es &\bs Item 4 \es &\bs Item 5 \es &\bs Item 6 \es &\bs Item 7 \es \\
    \hline \endhead
    \hline \endfoot
    \hline \endlastfoot
A name that is short    &\citep{Somecite}   &Locaville  &100    &   &x  &   &   &   &   &\\
Some name that is relatively long, but alright  &\citep{Anothercite}    &Abroad & 900 m &   &x  &   &   &x &    &\\
\end{longtable}


\bibliographystyle{plainnat}
\bibliography{database} 

\end{document}

1 Answer 1

2

Your citations are in a c column and that won't spread itself over multiple lines, unlike a p column.

To get a centered p type column, load the array package and add >{\centering\arraybackslash} before the p declaration. Alternatively, additionally load the ragged2e package and use its \Centering command instead of \centering, this allows better breaking of lines with more potential hyphenation points. In the following, I have done this and made your first column \RaggedRight. I have also adjusted column widths so the table fits better on the page.

Sample output

\begin{filecontents*}{database.bib}
@article{Somecite,
    author = {First Last and Fname Lname and F.N. Somename},
    title = {Title of this wonderful article},
    journal = {Unknown journal},
    volume = {2},
    number = {5},
    pages = {100--101},
    year = {1901}
}
@misc{Anothercite,
    author = {{Company Has A Terrible Long Abbreviation (CHATLA)}},
    title = {CHATLNAA does everything for you},
    howpublished = {\url{http://www.chatlnaa.com}},
    year = {2017},
    note = {Accessed today}
}
\end{filecontents*}

\documentclass[a4paper]{report}
\usepackage[authoryear,round,semicolon,sort]{natbib}
%\usepackage[numbers,square,comma,sort]{natbib}
\usepackage{longtable,array}
\usepackage{rotating}
\usepackage{ragged2e}

\newcommand{\bs}{\begin{sideways}}
\newcommand{\es}{\end{sideways}}

\begin{document}

Here is some text, and we refer to \citep{Somecite}. \Citet{Anothercite} is there too. See table.

\scriptsize
\begin{longtable}{|>{\RaggedRight\arraybackslash}p{2cm}>{\Centering\arraybackslash}p{1.5cm}p{1.5cm}c|p{0.16cm}p{0.16cm}p{0.16cm}p{0.16cm}p{0.16cm}p{0.16cm}p{0.16cm}|}
    \caption{Overview of a table with a lot of numbers.}\label{tbl:numbers} \\
    \hline
    Name &  &Location   &Number 1   & \multicolumn{7}{c|}{Items} \\
                        &   &                   &               &\bs Item 1 \es &\bs Item 2 \es &\bs Item 3 \es &\bs Item 4 \es &\bs Item 5 \es &\bs Item 6 \es &\bs Item 7 \es \\
    \hline \endhead
    \hline \endfoot
    \hline \endlastfoot
A name that is short    &\citep{Somecite}   &Locaville  &100    &   &x  &   &   &   &   &\\
Some name that is relatively long, but alright  &\citep{Anothercite}    &Abroad & 900 m &   &x  &   &   &x &    &\\
\end{longtable}


\bibliographystyle{plainnat}
\bibliography{database} 

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .