1

I was googling for an issue to manage references in LaTeX with natbib package and fortunately I got the same issue asked by Bartłomiej Stępień and Alan Munn gave an excellent answer to that question which can be found here.

I actually need square brackets around the reference number rather than period and to achieve that I just did

\patchcmd{\@lbibitem}{\item[}{\item[\hfil\stepcounter{bibcount}{[\thebibcount]}}{}{}

Now, everything works well to me too except an issue. The reference numbers now looks

enter image description here

As it can be noticed above the number [9] is not on the same right level as the number [10] is, that is I want these reference numbers right aligned as below. As well as I also want to reduce the distance between the reference number and the text which you can noticed in the following example.

enter image description here

It would be great if anyone could answer this question.

I greatly appreciate your time and effort.

The following is a short, compliable code but my .bst file is also customized.

\documentclass[12pt, openany]{book}
\usepackage{etoolbox}
\usepackage[round,sort,comma]{natbib}
\newcounter{bibcount}
\usepackage{hyperref,url}
\usepackage [english]{babel}

\makeatletter
\patchcmd{\@lbibitem}{\item[}{\item[\hfill\stepcounter{bibcount}{[\thebibcount]}}{}{}
\setlength{\bibhang}{2.00\parindent}
\renewcommand\NAT@bibsetup%
[1]{\setlength{\leftmargin}{\bibhang}\setlength{\itemindent}{-\parindent}%
\setlength{\itemsep}{\bibsep}\setlength{\parsep}{\z@}}
\makeatother

\bibliographystyle{refStyle}

\begin{document}
\noindent
These are the materials in Algebra:
\\~\\
\cite{MR1034353}.
\\~\\
\cite{MR600654}.
\\~\\
These are the materials in Complex Analysis:
\\~\\
\cite{MR510197}.
\\~\\
\cite{MR2730573}.
\\~\\
\cite{MR1344449}.
\\~\\
These are the materials in Real Analysis and Probability:
\\~\\
\cite{MR2893652}.
\\~\\
\cite{MR1681462}.
\\~\\
\cite{MR1121940}.
\\~\\
These are the materials in PDE:
\\~\\
\cite{MR2597943}.
\\~\\
\cite{MR1121940}.
\\~\\
And, finally these are the materials in Topology:
\\~\\
\cite{MR0464128}.
\\~\\
\cite{MR0163320}.

\bibliography{bibRef}
\thispagestyle{myheadings}
\pagestyle{headings} \thispagestyle{headings}

\end{document} 

The bibRef.bib file is the following:

@book {MR510197,
AUTHOR = {Ahlfors, Lars V.},
TITLE = {Complex analysis},
EDITION = {Third},
NOTE = {An introduction to the theory of analytic functions of one
complex variable,
International Series in Pure and Applied Mathematics},
PUBLISHER = {McGraw-Hill Book Co., New York},
YEAR = {1978},
PAGES = {xi+331},
ISBN = {0-07-000657-1},
MRCLASS = {30-01},
MRNUMBER = {510197},
}
@book {MR2730573,
AUTHOR = {Ahlfors, Lars V.},
TITLE = {Conformal invariants},
NOTE = {Topics in geometric function theory,
Reprint of the 1973 original,
With a foreword by Peter Duren, F. W. Gehring and Brad Osgood},
PUBLISHER = {AMS Chelsea Publishing, Providence, RI},
YEAR = {2010},
PAGES = {xii+162},
ISBN = {978-0-8218-5270-5},
MRCLASS = {30-02},
MRNUMBER = {2730573},
URL = {https://doi.org/10.1090/chel/371},
}
@book {MR2893652,
AUTHOR = {Billingsley, Patrick},
TITLE = {Probability and measure},
SERIES = {Wiley Series in Probability and Statistics},
NOTE = {Anniversary edition [of MR1324786],
With a foreword by Steve Lalley and a brief biography of
Billingsley by Steve Koppes},
PUBLISHER = {John Wiley \& Sons, Inc., Hoboken, NJ},
YEAR = {2012},
PAGES = {xviii+624},
ISBN = {978-1-118-12237-2},
MRCLASS = {60-01 (28-01)},
MRNUMBER = {2893652},
}
@book {MR1344449,
AUTHOR = {Conway, John B.},
TITLE = {Functions of one complex variable. {II}},
SERIES = {Graduate Texts in Mathematics},
VOLUME = {159},
PUBLISHER = {Springer-Verlag, New York},
YEAR = {1995},
PAGES = {xvi+394},
ISBN = {0-387-94460-5},
MRCLASS = {30-01},
MRNUMBER = {1344449},
MRREVIEWER = {P. Lappan},
URL = {https://doi.org/10.1007/978-1-4612-0817-4},
}
@book {MR2597943,
AUTHOR = {Evans, Lawrence C.},
TITLE = {Partial differential equations},
SERIES = {Graduate Studies in Mathematics},
VOLUME = {19},
EDITION = {Second},
PUBLISHER = {American Mathematical Society, Providence, RI},
YEAR = {2010},
PAGES = {xxii+749},
ISBN = {978-0-8218-4974-3},
MRCLASS = {35-01},
MRNUMBER = {2597943},
MRREVIEWER = {Diego M. Maldonado},
URL = {https://doi.org/10.1090/gsm/019},
}
@book {MR1681462,
AUTHOR = {Folland, Gerald B.},
TITLE = {Real analysis},
SERIES = {Pure and Applied Mathematics (New York)},
EDITION = {Second},
NOTE = {Modern techniques and their applications,
A Wiley-Interscience Publication},
PUBLISHER = {John Wiley \& Sons, Inc., New York},
YEAR = {1999},
PAGES = {xvi+386},
ISBN = {0-471-31716-0},
MRCLASS = {00A05 (26-01 28-01 46-01)},
MRNUMBER = {1681462},
}
@article {MR1034353,
AUTHOR = {Hungerford, Thomas W.},
TITLE = {A counterexample in {G}alois theory},
JOURNAL = {Amer. Math. Monthly},
FJOURNAL = {American Mathematical Monthly},
VOLUME = {97},
YEAR = {1990},
NUMBER = {1},
PAGES = {54--57},
ISSN = {0002-9890},
MRCLASS = {12F10},
MRNUMBER = {1034353},
URL = {https://doi.org/10.2307/2324007},
}
@book {MR600654,
AUTHOR = {Hungerford, Thomas W.},
 TITLE = {Algebra},
SERIES = {Graduate Texts in Mathematics},
VOLUME = {73},
  NOTE = {Reprint of the 1974 original},
 PUBLISHER = {Springer-Verlag, New York-Berlin},
  YEAR = {1980},
 PAGES = {xxiii+502},
  ISBN = {0-387-90518-9},
   MRCLASS = {00A05 (15-01 16-01)},
  MRNUMBER = {600654},
}
@book {MR1121940,
AUTHOR = {Karatzas, Ioannis and Shreve, Steven E.},
TITLE = {Brownian motion and stochastic calculus},
SERIES = {Graduate Texts in Mathematics},
VOLUME = {113},
EDITION = {Second},
PUBLISHER = {Springer-Verlag, New York},
YEAR = {1991},
PAGES = {xxiv+470},
ISBN = {0-387-97655-8},
MRCLASS = {60J65 (35K99 35R60 60G44 60H10 60J60)},
MRNUMBER = {1121940},
URL = {https://doi.org/10.1007/978-1-4612-0949-2},
}
@book {MR0464128,
AUTHOR = {Munkres, James R.},
TITLE = {Topology: a first course},
PUBLISHER = {Prentice-Hall, Inc., Englewood Cliffs, N.J.},
YEAR = {1975},
PAGES = {xvi+413},
MRCLASS = {54-01},
MRNUMBER = {0464128},
}
@book {MR0163320,
AUTHOR = {Munkres, James R.},
TITLE = {Elementary differential topology},
SERIES = {Lectures given at Massachusetts Institute of Technology, Fall},
VOLUME = {1961},
PUBLISHER = {Princeton University Press, Princeton, N.J.},
YEAR = {1963},
PAGES = {xi+107pp},
MRCLASS = {57.00 (53.45)},
MRNUMBER = {0163320},
MRREVIEWER = {M. W. Hirsch},
}

And, the output file looks like the following:

enter image description here

enter image description here

enter image description here

As it can be seen that the right big bracket symbol, i.e., ] for numbers 9 and 10 are not on the same vertical line, i.e., they are not right aligned but I wanted them to be right aligned.

1

The problem here is that the definition of \@lbibitem contains a \hfil we have to delete. So add the following patch to your preamble:

\patchcmd{\@lbibitem}%
  {\hfil \NAT@anchor {#2}{\NAT@num }]}%
  {]}% <=================================================================
  {}%
  {}

With the following MWE

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book {MR510197,
AUTHOR = {Ahlfors, Lars V.},
TITLE = {Complex analysis},
EDITION = {Third},
NOTE = {An introduction to the theory of analytic functions of one
complex variable,
International Series in Pure and Applied Mathematics},
PUBLISHER = {McGraw-Hill Book Co., New York},
YEAR = {1978},
PAGES = {xi+331},
ISBN = {0-07-000657-1},
MRCLASS = {30-01},
MRNUMBER = {510197},
}
@book {MR2730573,
AUTHOR = {Ahlfors, Lars V.},
TITLE = {Conformal invariants},
NOTE = {Topics in geometric function theory,
Reprint of the 1973 original,
With a foreword by Peter Duren, F. W. Gehring and Brad Osgood},
PUBLISHER = {AMS Chelsea Publishing, Providence, RI},
YEAR = {2010},
PAGES = {xii+162},
ISBN = {978-0-8218-5270-5},
MRCLASS = {30-02},
MRNUMBER = {2730573},
URL = {https://doi.org/10.1090/chel/371},
}
@book {MR2893652,
AUTHOR = {Billingsley, Patrick},
TITLE = {Probability and measure},
SERIES = {Wiley Series in Probability and Statistics},
NOTE = {Anniversary edition [of MR1324786],
With a foreword by Steve Lalley and a brief biography of
Billingsley by Steve Koppes},
PUBLISHER = {John Wiley \& Sons, Inc., Hoboken, NJ},
YEAR = {2012},
PAGES = {xviii+624},
ISBN = {978-1-118-12237-2},
MRCLASS = {60-01 (28-01)},
MRNUMBER = {2893652},
}
@book {MR1344449,
AUTHOR = {Conway, John B.},
TITLE = {Functions of one complex variable. {II}},
SERIES = {Graduate Texts in Mathematics},
VOLUME = {159},
PUBLISHER = {Springer-Verlag, New York},
YEAR = {1995},
PAGES = {xvi+394},
ISBN = {0-387-94460-5},
MRCLASS = {30-01},
MRNUMBER = {1344449},
MRREVIEWER = {P. Lappan},
URL = {https://doi.org/10.1007/978-1-4612-0817-4},
}
@book {MR2597943,
AUTHOR = {Evans, Lawrence C.},
TITLE = {Partial differential equations},
SERIES = {Graduate Studies in Mathematics},
VOLUME = {19},
EDITION = {Second},
PUBLISHER = {American Mathematical Society, Providence, RI},
YEAR = {2010},
PAGES = {xxii+749},
ISBN = {978-0-8218-4974-3},
MRCLASS = {35-01},
MRNUMBER = {2597943},
MRREVIEWER = {Diego M. Maldonado},
URL = {https://doi.org/10.1090/gsm/019},
}
@book {MR1681462,
AUTHOR = {Folland, Gerald B.},
TITLE = {Real analysis},
SERIES = {Pure and Applied Mathematics (New York)},
EDITION = {Second},
NOTE = {Modern techniques and their applications,
A Wiley-Interscience Publication},
PUBLISHER = {John Wiley \& Sons, Inc., New York},
YEAR = {1999},
PAGES = {xvi+386},
ISBN = {0-471-31716-0},
MRCLASS = {00A05 (26-01 28-01 46-01)},
MRNUMBER = {1681462},
}
@article {MR1034353,
AUTHOR = {Hungerford, Thomas W.},
TITLE = {A counterexample in {G}alois theory},
JOURNAL = {Amer. Math. Monthly},
FJOURNAL = {American Mathematical Monthly},
VOLUME = {97},
YEAR = {1990},
NUMBER = {1},
PAGES = {54--57},
ISSN = {0002-9890},
MRCLASS = {12F10},
MRNUMBER = {1034353},
URL = {https://doi.org/10.2307/2324007},
}
@book {MR600654,
AUTHOR = {Hungerford, Thomas W.},
 TITLE = {Algebra},
SERIES = {Graduate Texts in Mathematics},
VOLUME = {73},
  NOTE = {Reprint of the 1974 original},
 PUBLISHER = {Springer-Verlag, New York-Berlin},
  YEAR = {1980},
 PAGES = {xxiii+502},
  ISBN = {0-387-90518-9},
   MRCLASS = {00A05 (15-01 16-01)},
  MRNUMBER = {600654},
}
@book {MR1121940,
AUTHOR = {Karatzas, Ioannis and Shreve, Steven E.},
TITLE = {Brownian motion and stochastic calculus},
SERIES = {Graduate Texts in Mathematics},
VOLUME = {113},
EDITION = {Second},
PUBLISHER = {Springer-Verlag, New York},
YEAR = {1991},
PAGES = {xxiv+470},
ISBN = {0-387-97655-8},
MRCLASS = {60J65 (35K99 35R60 60G44 60H10 60J60)},
MRNUMBER = {1121940},
URL = {https://doi.org/10.1007/978-1-4612-0949-2},
}
@book {MR0464128,
AUTHOR = {Munkres, James R.},
TITLE = {Topology: a first course},
PUBLISHER = {Prentice-Hall, Inc., Englewood Cliffs, N.J.},
YEAR = {1975},
PAGES = {xvi+413},
MRCLASS = {54-01},
MRNUMBER = {0464128},
}
@book {MR0163320,
AUTHOR = {Munkres, James R.},
TITLE = {Elementary differential topology},
SERIES = {Lectures given at Massachusetts Institute of Technology, Fall},
VOLUME = {1961},
PUBLISHER = {Princeton University Press, Princeton, N.J.},
YEAR = {1963},
PAGES = {xi+107pp},
MRCLASS = {57.00 (53.45)},
MRNUMBER = {0163320},
MRREVIEWER = {M. W. Hirsch},
}
\end{filecontents*}


\documentclass[12pt, openany]{book}

\usepackage[english]{babel}
\usepackage{etoolbox}
\usepackage[round,sort,comma]{natbib}
\newcounter{bibcount}
\usepackage{url,hyperref}

\makeatletter
\patchcmd{\@lbibitem}%
  {\item[}%
  {\item[\hfill\stepcounter{bibcount}{[\thebibcount]}}% <================
  {}%
  {}
\patchcmd{\@lbibitem}%
  {\hfil \NAT@anchor {#2}{\NAT@num }]}%
  {]}% <=================================================================
  {}%
  {}
\setlength{\bibhang}{2.00\parindent}
\renewcommand\NAT@bibsetup[1]{%
  \setlength{\leftmargin}{\bibhang}%
  \setlength{\itemindent}{-\parindent}%
  \setlength{\itemsep}{\bibsep}%
  \setlength{\parsep}{\z@}%
}
\makeatother

\bibliographystyle{plainnat} % refStyle

\begin{document}
\noindent
These are the materials in Algebra:
\\~\\
\cite{MR1034353}.
\\~\\
\cite{MR600654}.
\\~\\
These are the materials in Complex Analysis:
\\~\\
\cite{MR510197}.
\\~\\
\cite{MR2730573}.
\\~\\
\cite{MR1344449}.
\\~\\
These are the materials in Real Analysis and Probability:
\\~\\
\cite{MR2893652}.
\\~\\
\cite{MR1681462}.
\\~\\
\cite{MR1121940}.
\\~\\
These are the materials in PDE:
\\~\\
\cite{MR2597943}.
\\~\\
\cite{MR1121940}.
\\~\\
And, finally these are the materials in Topology:
\\~\\
\cite{MR0464128}.
\\~\\
\cite{MR0163320}.

\bibliography{\jobname}
\thispagestyle{myheadings}
\pagestyle{headings} \thispagestyle{headings}

\end{document}

you get the wished result:

wished result

  • Excellent! It does perfectly work as I needed. Thank you very much for your helping hands. I really appreciate it! – CMP Nov 30 '17 at 3:42

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.