20

I am writing a bibliography :

\begin{thebibliography}{9}
\bibitem{Lorem}\textsc{Lorem ipsum dolor sit}
\texttt{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae purus mi. Fusce quam urna, elementum at ullamcorper in, tempus sed quam.}
\end{thebibliography}

The result :

enter image description here

And what I would like to obtain :

enter image description here

I want to indent the second and the third line of \texttt. Do I have to redefine \texttt or is there an other solution?

Thank you for your help.

EDIT:

By using the solution of egreg I obtain a strange result :

enter image description here

Michaël
  • 385

2 Answers2

13

The LaTeX internals can be modified to allow this. We modify:

  • \@biblabel that prints the label, the new one includes a space of the length \bibindent

  • \bibitem that prints the whole title, to remove the extra space for the first line

  • You should add \kern\bibindent into the parameter of \begin{thebibliography} so that the indentation is ensured

  • The line \def\bibindent defines the amount of indentation, I set it to 1em.

The code:

\documentclass{article}
\begin{document}

\def\bibindent{1em}
\begin{thebibliography}{99\kern\bibindent}
\makeatletter
\let\old@biblabel\@biblabel
\def\@biblabel#1{\old@biblabel{#1}\kern\bibindent}
\let\old@bibitem\bibitem
\def\bibitem#1{\old@bibitem{#1}\leavevmode\kern-\bibindent}
\makeatother

\bibitem{Lorem}\textsc{Lorem ipsum dolor sit}
\texttt{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae purus mi. Fusce quam urna, elementum at ullamcorper in, tempus sed quam.}
\end{thebibliography}

\end{document}
yo'
  • 51,322
  • I used this to do the opposite - remove indent, thanks. Using \documentclass[openbib]{memoir} results in bibliography indents that I didn't want. Adding \def\bibindent{0em} before \begin{document} fixed it. – Cog77 Aug 19 '15 at 11:13
11

You can use the enumitem package to redefine the environment:

\documentclass[a4paper]{article}
\usepackage{enumitem}
\makeatletter
\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
      \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \begin{enumerate}[label={[\arabic{enumi}]},itemindent=*,leftmargin=4em]
      \@openbib@code
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \end{enumerate}}
\makeatother

\begin{document}

\begin{thebibliography}{99}

\bibitem{Lorem}\textsc{Lorem ipsum dolor sit} \texttt{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras
vitae purus mi. Fusce quam urna, elementum at ullamcorper in, tempus sed quam.}

\bibitem{Lorem2}\textsc{Lorem ipsum dolor sit} \texttt{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras
vitae purus mi. Fusce quam urna, elementum at ullamcorper in, tempus sed quam.}

\end{thebibliography}

\end{document}

Adjust the value for leftmargin to suit you. Notice that the argument to thebibliography is still necessary, even if it does nothing. This way you won't need to modify the input if you change your mind.

enter image description here

Caveat

This code is meant for the standard class article. For report or book change \section into \chapter, while for KoMa-script classes or memoir some different hack might be necessary.

egreg
  • 1,121,712
  • Does it matter if one uses counter enumi (1) or counter enumiv (4)? The latter counter is employed by LaTeX's main document classes in the construction of the bibliography list. Just curious. – Mico Apr 09 '12 at 16:49
  • @Mico I guess one can even use label={[\arabic*]}, in this case. I didn't want to go too far away from the usual setting. Probably the standard classes choose enumiv because it's rarely used in the document. – egreg Apr 09 '12 at 16:53