5

The bibliography environment results in a list.

However, I want to produce a tabular with two columns. The first column is the id, like 1, 2..., and the second column is the content of the bib.

Any one have a solution?

This result should look like:

----------------------
| 1 | this is bib one |
----------------------
| 2 | this is bib two |
----------------------

UPDATE:

I try to code from scratch, and get a workable solution.

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}

\makeatletter
\renewcommand\@biblabel[1]{#1}
\newenvironment{tablebibliography}%
{\center\tabularx{\textwidth}{|c|X|}\hline%
\setcounter{enumiv}{0}%
\let\p@enumiv\@empty%
\renewcommand\theenumiv{\@arbic\c@enumiv}}%
{%\\\hline
\endtabularx\endcenter}

\def\@@preparetbibitem{%
\addtocounter{enumiv}{1}%
\ifnum\the\value{enumiv}>1\\\hline\fi}

\def\tbibitem{\@ifnextchar[\@tlbibitem\@tbibitem}
\def\@tlbibitem[#1]#2{\@@preparetbibitem\@biblabel{#1} & \if@filesw%
{\let\protect\noexpand\immediate\write\@auxout%
{\string\bibcite{#2}{#1}}}\fi\ignorespaces}

\def\@tbibitem#1{\@@preparetbibitem\@biblabel{\the\value{enumiv}} & \if@filesw%
\immediate\write\@auxout%
{\string\bibcite{#1}{\the\value{enumiv}}}\fi\ignorespaces}
\makeatother

\begin{document}
This is reference\cite{itemone}, this is another reference\cite{itemtwo}.
\begin{tablebibliography}
\tbibitem{itemone} first item
\tbibitem[label]{itemtwo} second item
\tbibitem{itemthree} 3rd item \\\hline
\end{tablebibliography}
\end{document}

However, there are two issues:

  • the 1st cell of the 1st line is not center-aligned.
  • I must add \\\hline at the end of the last item, because I can't put it before \endtabularx, or it will complain \hline noalign.

How to solve these problems?

UPDATE:

I replace tabularx with tabu, and the problems metioned above are solved. But the \cite link is broken. I don't kown how the \bibitem defines the link destination, so, what is the \label counterpart for \cite as to \ref?

\usepackage{longtable}
\usepackage{tabu}
\newenvironment{tablebibliography}%
{\center\longtabu to \textwidth{|X[-1,c]|X[1,p]|}\hline%
\setcounter{enumiv}{0}%
\let\p@enumiv\@empty%
\renewcommand\theenumiv{\@arbic\c@enumiv}}%
{\\\hline
\endlongtabu\endcenter}

UPDATE:

I solved the link problem.

\def\@tbiblink#1{%
\Hy@raisedlink{\hyper@anchorstart{cite.#1}\relax\hyper@anchorend}}

So \cite or \hyper@link links to \@tbiblink.

  • What is wrong with the current format? – Thorsten Donig Mar 4 '14 at 16:23
  • @ThorstenDonig, I have a .doc document, and I am trying to rewrite it in latex. The bib-list is a table by its original format, so I have no choice. – Martin Wang Mar 4 '14 at 16:29
  • 2
    The fact that it is a table in that document doesn't necessarily mean that you need a table in a LaTeX document. But until now you didn't show how the bibliography looks. – Thorsten Donig Mar 4 '14 at 16:31
  • @ThorstenDonig, I just want to fit bib list in a table, I have revised the question. – Martin Wang Mar 4 '14 at 16:37
  • 1
    You example doesn't belong to biblatex. It seems you just want to use a manual bibliography. Is this correct? – Marco Daniel Mar 4 '14 at 19:42
4

bib tabular

With tabular I could do it directly, but with tabularx I needed the environ package to collect the body. However hyperref links via \cite do not work, this is another matter.

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{environ}

\newcounter{tbib}

\makeatletter
\def\tbibitem{\ifnum\value{tbib}>0 \expandafter\\\fi
              \refstepcounter{tbib}%
              \@ifnextchar[\@ltbibitem\@tbibitem}

\def\@ltbibitem[#1]#2{\if@filesw {\let\protect\noexpand
                      \immediate\write\@auxout{\string\bibcite{#2}{#1}}}\fi 
                      #1&}

\def\@tbibitem#1{\if@filesw \immediate\write\@auxout
                  {\string\bibcite{#1}{\the\value{tbib}}}\fi 
                 \arabic{tbib}&}
\makeatother

\NewEnviron{thetablebibliography}%
{\setcounter{tbib}{0}%
 \let\bibitem\tbibitem
 \begin{center}
 \begin{tabularx}{\textwidth}{|c|X|}
 \hline \BODY\\\hline
 \end{tabularx}\end{center}}

\makeatother

%% but \cite does not create valid links with 
%% \usepackage{hyperref}

\begin{document}\thispagestyle{empty}
This is reference~\cite{itemone}, this is another reference~\cite{itemtwo}.

\begin{thetablebibliography}
\bibitem{itemone} first item
\bibitem[label]{itemtwo} second item
\bibitem{itemthree} 3rd item
\end{thetablebibliography}

\end{document}
% version avec tabular qui marche sans environ 
% \def\tbibitem{\tbibnewline\refstepcounter{tbib}%
%               \@ifnextchar[\@ltbibitem\@tbibitem}
% \newenvironment{thetablebibliography}%
% {\setcounter{tbib}{0}%
%  \let\bibitem\tbibitem
%  \def\tbibnewline{\gdef\tbibnewline{\tabularnewline}}%
%  \begin{center}
%  \begin{tabular}{|c|c|}
%  \hline }
% {\\\hline\end{tabular}\end{center}}
  • tabular is weak, so I choose tabu, which combines longtable and tabularx. – Martin Wang Mar 6 '14 at 19:36
  • @MartinWang: You can also try ltxtable, since tabu has it's own problems... – Werner Mar 6 '14 at 19:52
  • @Werner, the syntax of \LTXtable is a little wierd. In my case, I have to write file in code to make it clean. – Martin Wang Mar 6 '14 at 20:13
0

The final solution is presented. May be ltxtable is better than tabu, but it's not an issue for now.

\documentclass{article}

\usepackage{hyperref}
\usepackage{tabu}
\usepackage{longtable}
\newcommand\usetablebibliography{%
\renewenvironment{thebibliography}[1]{\begin{tablebibliography}}{\end{tablebibliography}}%
\renewcommand{\bibitem}{\tbibitem}%
}%
\makeatletter
\newcommand\settablebibheader[2]{\providecommand\tbibheaderone{#1}\providecommand\tbibheadertwo{#2}}
\renewcommand\@biblabel[1]{#1}
\newenvironment{tablebibliography}%
{\center\longtabu to \textwidth{|X[-1,c]|X[1,p]|}\hline%
\setcounter{enumiv}{0}%
\let\p@enumiv\@empty%
\renewcommand\theenumiv{\@arbic\c@enumiv}%
\@ifundefined{tbibheaderone}{}{\tbibheaderone & \tbibheadertwo \\\hline}%
}%
{\\\hline
\endlongtabu\endcenter}

\def\@@preparetbibitem{%
\addtocounter{enumiv}{1}%
\ifnum\the\value{enumiv}>1\\\hline\fi}

\def\@tbiblink#1{%
\Hy@raisedlink{\hyper@anchorstart{cite.#1}\relax\hyper@anchorend}}

\def\tbibitem{\@ifnextchar[\@tlbibitem\@tbibitem}

\def\@tlbibitem[#1]#2{\@@preparetbibitem\@tbiblink{#2}\@biblabel{#1} & \if@filesw%
{\let\protect\noexpand\immediate\write\@auxout%
{\string\bibcite{#2}{#1}}}\fi\ignorespaces}

\def\@tbibitem#1{\@@preparetbibitem\@tbiblink{#1}\@biblabel{\the\value{enumiv}} & \if@filesw%
\immediate\write\@auxout%
{\string\bibcite{#1}{\the\value{enumiv}}}\fi\ignorespaces}
\makeatother


\begin{filecontents}{\jobname.bib}
@Book{test1,
    author    = {Goossens, Michel and Mittelbach,
        Frank and Samarin, Alexander},
    title     = {The LaTeX Companion},
    publisher = {Addison-Wesley},
    location  = {Reading, Mass.},
    year      = {1994},
}
\end{filecontents}

\begin{document}

this is a citation\cite{test1}

\settablebibheader{header1}{header2}
\usetablebibliography
\bibliographystyle{unsrt}
\bibliography{\jobname}
\end{document}

The compile command is:

pdflatex test
bibtex   test
pdflatex test
pdflatex test

And the result looks like:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.