right aligned reference labels with multibib - reference
I am using multibib to include a reference list after each section. I added some code in order to make the reference labels look like [a.1],[a.2], ... where a is the section number.
It looks like the reference labels are left-aligned, which makes the text of the reference shift to the right, when having more than 9 entries.
I would like to have the labels right-aligned, such that the text after the label starts always at the same position. Is there an option in multibib I overlooked?
It is highly likely, that this is not exactly a mwe.
Thank you for your help
My texfile.tex is:
\documentclass[10pt,letterpaper]{article}
\usepackage[numbers,square,comma]{natbib}
\usepackage[resetlabels]{multibib}
\usepackage{totcount}
\newcites{sec}{Refs: Section 1}
\newcommand\newcite[3]{\citetext{\ref{#1}:\citealp#2{#3}}}
\renewcommand\bibsection{\subsection{\refname}}
\makeatletter
\newtotcounter{citenum}
\def\#mb#citenamelist{cite,citep,citet,citealp,citealt,citepalias,citetalias}
\makeatother
\pagestyle{plain}
\begin{document}
\section{Section 1}\label{sec:sec1}
\makeatletter
\renewcommand{\#biblabel}[1]{[\ref{sec:sec1}:\stepcounter{citenum}#1]}
\makeatother
\renewcommand{\newcite}[1]{\citetext{\ref{sec:sec1}:\citealpsec{#1}}}
\subsection{Subsection 1}
\noindent\newcite{knuth1986texbook1}
\noindent\newcite{knuth1986texbook2}
\noindent\newcite{knuth1986texbook3}
\noindent\newcite{knuth1986texbook4}
\noindent\newcite{knuth1986texbook5}
\noindent\newcite{knuth1986texbook6}
\noindent\newcite{knuth1986texbook7}
\noindent\newcite{knuth1986texbook8}
\noindent\newcite{knuth1986texbook9}
\noindent\newcite{knuth1986texbook10}
\bgroup
\let\section\subsection
\bibliographystylesec{unsrt}
\bibliographysec{bibfile}
\egroup
\end{document}
My bibfile.bib is:
#book{knuth1986texbook1,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook2,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook3,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook4,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook5,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook6,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook7,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook8,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook9,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
#book{knuth1986texbook10,
title={The texbook},
author={Knuth, Donald Ervin and Bibby, Duane},
volume={1993},
year={1986},
publisher={Addison-Wesley Reading, MA, USA}
}
The evolved solution to this problem was suggested by egreg on Feb 13 2013 Link to the stackexchange site
\usepackage{etoolbox}
\makeatletter
\patchcmd{\thebibliography}{%
\section*{\refname}\#mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
}{}{}{}
\begingroup\catcode`#=12
\AtBeginDocument{
\patchcmd\thebibliography
{\advance\#tempcnta#1}
{\advance\#tempcnta#1\else\#tempcnta#1}
{}{}
}
\endgroup
\makeatother
Related
Empty bibliography and citation undefined
I'm writting my bachelor thesis and I encountered a problem with the bibliography. I've tried many different solutions (including changing Texmaker configurations, reinstallating Texmaker and so on). Nothing helped. There're always "Citation 'shabbir2010' [..] undefined" and "Empty bibliography" errors. my code: \documentclass[12pt, oneside, a4paper]{report} \usepackage[cp1250]{inputenc} \usepackage{polski} \usepackage[T1]{fontenc} \usepackage{txfonts} \usepackage{textcomp} \usepackage[left=3cm, right=2cm, top=2cm, bottom=2cm, headsep=1cm]{geometry} \usepackage{graphicx} \usepackage{indentfirst} \usepackage[style=numeric, sorting=none]{biblatex} \addbibresource{cytowania.bib} \linespread{1.3} \begin{document} my content \cite{shabbir2010} \printbibliography \end{document} my .bib file (from Google Scholar): #article{shabbir2010, author = {Shabbir, G and Khan, H and Sadiq, MA}, title = {A note on Exact solution of SIR and SIS epidemic models}, journal = {arXiv preprint arXiv:1012.5035}, date = {2010}, keywords = {trusted}, } I have Windows 10 and Texmaker 5.0.4. Please help..
Python regex group sentences by person's name
I have the following text: "- Nike: Hey, where are you?\n10/6/20, 8:51 - Mike: Soon\n10/6/20, 8:55 - Nike: how are you guy?\n10/4/20, 8:55 - Mike: It's okay\n10/4/20, 9:05" I'd like to make 2 lists like the following: nike = ["Hey, where are you?", "how are you guy?"] mike = ["Soon", "It's okay"] Any idea how I could do such thing please? Thanks guys!
import re s = "- Nike: Hey, where are you?\n10/6/20, 8:51 - Mike: Soon\n10/6/20, 8:55 - Nike: how are you guy?\n10/4/20, 8:55 - Mike: It's okay\n10/4/20, 9:05" out = {} for name, sentence in re.findall(r'([A-Za-z]+):\s*(.*)$', s, flags=re.M): out.setdefault(name, []).append(sentence) print(out) Prints: {'Nike': ['Hey, where are you?', 'how are you guy?'], 'Mike': ['Soon', "It's okay"]}
Replace Pattern matching portion with some other value in python 3
I want to replace ROAD with RD addr = ['100 NORTH MAIN ROAD', '100 BROAD ROAD APT.', 'SAROJINI DEVI ROAD', 'BROAD AVENUE ROAD'] Output output : ['100 NORTH MAIN RD.', '100 BROAD RD. APT.', 'SAROJINI DEVI RD.', 'BROAD AVENUE RD.'] i tried below mentioned code new_address=[word.replace("ROAD","RD") for word in addr] but not getting desired output (BROAD is also getting replaces by RD.) ['100 NORTH MAIN RD.', '100 BRD. RD. APT.', 'SAROJINI DEVIRD.', 'BRD. AVENUE RD.']
In this current example can do: new_address=[word.replace(" ROAD"," RD.") for word in addr] Or in general sence, use regex: new_address = [re.sub(r'\bROAD\b', 'RD.', w) for w in l] # ['100 NORTH MAIN RD.', '100 BROAD RD. APT.', 'SAROJINI DEVI RD.', # 'BROAD AVENUE RD.']
Using unstack with Pandas
I am getting an exception when applying unstack, and would like to understand it. For a reproducible example: (to load the data: pd.DataFrame(json.loads(titanic))) titanic '{"home.dest":{"0":"St Louis, MO","1":"Montreal, PQ \\/ Chesterville, ON","2":"Montreal, PQ \\/ Chesterville, ON","3":"Montreal, PQ \\/ Chesterville, ON","4":"Montreal, PQ \\/ Chesterville, ON","5":"New York, NY","6":"Hudson, NY","7":"Belfast, NI","8":"Bayside, Queens, NY","9":"Montevideo, Uruguay","10":"New York, NY","11":"New York, NY","12":"Paris, France","13":null,"14":"Hessle, Yorks","15":"New York, NY","16":"Montreal, PQ","17":"Montreal, PQ","18":null,"19":"Winnipeg, MN"},"pclass":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1,"18":1,"19":1},"survived":{"0":1,"1":1,"2":0,"3":0,"4":0,"5":1,"6":1,"7":0,"8":1,"9":0,"10":0,"11":1,"12":1,"13":1,"14":1,"15":0,"16":0,"17":1,"18":1,"19":0},"name":{"0":"Allen, Miss. Elisabeth Walton","1":"Allison, Master. Hudson Trevor","2":"Allison, Miss. Helen Loraine","3":"Allison, Mr. Hudson Joshua Creighton","4":"Allison, Mrs. Hudson J C (Bessie Waldo Daniels)","5":"Anderson, Mr. Harry","6":"Andrews, Miss. Kornelia Theodosia","7":"Andrews, Mr. Thomas Jr","8":"Appleton, Mrs. Edward Dale (Charlotte Lamson)","9":"Artagaveytia, Mr. Ramon","10":"Astor, Col. John Jacob","11":"Astor, Mrs. John Jacob (Madeleine Talmadge Force)","12":"Aubart, Mme. Leontine Pauline","13":"Barber, Miss. Ellen \\"Nellie\\"","14":"Barkworth, Mr. Algernon Henry Wilson","15":"Baumann, Mr. John D","16":"Baxter, Mr. Quigg Edmond","17":"Baxter, Mrs. James (Helene DeLaudeniere Chaput)","18":"Bazzani, Miss. Albina","19":"Beattie, Mr. Thomson"},"sex":{"0":"female","1":"male","2":"female","3":"male","4":"female","5":"male","6":"female","7":"male","8":"female","9":"male","10":"male","11":"female","12":"female","13":"female","14":"male","15":"male","16":"male","17":"female","18":"female","19":"male"},"age":{"0":29.0,"1":0.92,"2":2.0,"3":30.0,"4":25.0,"5":48.0,"6":63.0,"7":39.0,"8":53.0,"9":71.0,"10":47.0,"11":18.0,"12":24.0,"13":26.0,"14":80.0,"15":null,"16":24.0,"17":50.0,"18":32.0,"19":36.0},"sibsp":{"0":0,"1":1,"2":1,"3":1,"4":1,"5":0,"6":1,"7":0,"8":2,"9":0,"10":1,"11":1,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0},"parch":{"0":0,"1":2,"2":2,"3":2,"4":2,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":1,"17":1,"18":0,"19":0},"ticket":{"0":"24160","1":"113781","2":"113781","3":"113781","4":"113781","5":"19952","6":"13502","7":"112050","8":"11769","9":"PC 17609","10":"PC 17757","11":"PC 17757","12":"PC 17477","13":"19877","14":"27042","15":"PC 17318","16":"PC 17558","17":"PC 17558","18":"11813","19":"13050"},"fare":{"0":211.3375,"1":151.55,"2":151.55,"3":151.55,"4":151.55,"5":26.55,"6":77.9583,"7":0.0,"8":51.4792,"9":49.5042,"10":227.525,"11":227.525,"12":69.3,"13":78.85,"14":30.0,"15":25.925,"16":247.5208,"17":247.5208,"18":76.2917,"19":75.2417},"cabin":{"0":"B5","1":"C22 C26","2":"C22 C26","3":"C22 C26","4":"C22 C26","5":"E12","6":"D7","7":"A36","8":"C101","9":null,"10":"C62 C64","11":"C62 C64","12":"B35","13":null,"14":"A23","15":null,"16":"B58 B60","17":"B58 B60","18":"D15","19":"C6"},"embarked":{"0":"S","1":"S","2":"S","3":"S","4":"S","5":"S","6":"S","7":"S","8":"S","9":"C","10":"C","11":"C","12":"C","13":"S","14":"S","15":"S","16":"C","17":"C","18":"C","19":"C"},"boat":{"0":"2","1":"11","2":null,"3":null,"4":null,"5":"3","6":"10","7":null,"8":"D","9":null,"10":null,"11":"4","12":"9","13":"6","14":"B","15":null,"16":null,"17":"6","18":"8","19":"A"},"body":{"0":null,"1":null,"2":null,"3":135.0,"4":null,"5":null,"6":null,"7":null,"8":null,"9":22.0,"10":124.0,"11":null,"12":null,"13":null,"14":null,"15":null,"16":null,"17":null,"18":null,"19":null}}' I create a multi index with the following command: titanic = titanic.set_index(['name', 'home.dest']) Then I want to unstack. titanic.unstack(level = 'home.dest') I get the following exception message: ValueError: Index contains duplicate entries, cannot reshape
The error is saying that your choice of columns in which you built the MultiIndex is not unique and therefore it has problems unstacking because there are ambiguities. One way to fix this is to guarantee the uniqueness by adding a counter. counts = titanic.gropuby(['name', 'home.dest']).cumcount().rename('Counter') titanic = titanic.set_index(['name', 'home.dest', counts]) Then your unstack will work titanic.unstack(level = 'home.dest') But I'd advise maybe titanic.unstack(['home.dest', 'Counter']) Otherwise, you'll have to aggregate with a groupby titanic.groupby(['name', 'home.dest']).first().unstack()
Caught: java.lang.StackOverflowError JsonBuilder closure
I've been trying to read an xml file and convert it to json using groovy's JsonBuilder. The problem is that when I print with def builder = new JsonBuilder(jsonObject) println builder.toPrettyString() I got a Caught: java.lang.StackOverflowError Here is the whole stacktrace Exception in thread "main" java.lang.StackOverflowError at groovy.json.JsonOutput.writeObject(JsonOutput.java:259) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) at groovy.json.JsonOutput.writeObject(JsonOutput.java:272) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) at groovy.json.JsonOutput.writeObject(JsonOutput.java:272) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) at groovy.json.JsonOutput.writeObject(JsonOutput.java:272) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) at groovy.json.JsonOutput.writeObject(JsonOutput.java:272) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) at groovy.json.JsonOutput.writeObject(JsonOutput.java:272) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) at groovy.json.JsonOutput.writeObject(JsonOutput.java:272) at groovy.json.JsonOutput.writeIterator(JsonOutput.java:442) Here the code. package firstgroovyproject import groovy.json.JsonBuilder class XmlToJsonII { static void main(def args){ def carRecords = ''' <records> <car name='HSV Maloo' make='Holden' year='2006'> <countries> <country> Austria </country> <country> Spain </country> </countries> <record type='speed'>Production Pickup Truck with speed of 271kph </record> </car> <car name='P50' make='Peel' year='1962'> <countries> <country> Monaco </country> </countries> <record type='size'>Smallest Street-Legal Car at 99cm wide and 59 kg in weight</record> </car> <car name='Royale' make='Bugatti' year='1931'> <record type='price'>Most Valuable Car at $15 million</record> <countries> <country> Italia </country> </countries> </car> <car name='Seat' make='Ibiza' year='1985'> <record type='price'>barato</record> <countries> <country> Spain </country> </countries> </car> </records> ''' def xmlRecords = new XmlSlurper().parseText(carRecords) def jsonObject = [:] jsonObject.records = [] def records = jsonObject.records xmlRecords.car.each {xmlCar -> records.add([ countries: xmlCar.countries.children().each{ country -> println "country : ${country.text()}" [country: country.text()] }, ]) } def builder = new JsonBuilder(jsonObject) println builder.toPrettyString() //println builder.toString() } }
tl;dr: Your second (inner) each should be a collect instead. The real answer: The return value of each is the original Iterable that invoked it. In this case that would be the XML object collection defined by the expression xmlCar.countries.children(). Since the objects in that collection contain references back to their own parents your JSON build causes an infinite regress that results in a stack overflow. This doesn't happen with your first (outer) use of each, because you are not using the return value. Instead you are adding to a preexisting list (records). By changing the second (inner) each into a collect, you are still iterating through the children of the countries elements. However, instead of returning the original XML children (the result of each) you are compiling and returning a list of maps of the form [country:"country_string_from_xml"], which seems to be the desired behavior. Confusing each and collect is a common rookie mistake in Groovy... which only made it all the more galling when it happened to ME last week. :-)