Bibliographystyle {unsrt} fails to sort citations properly - overleaf

I'm importing my references from Mendeley under 'references.bib'. I want to sort them to match the order in which the citations are used. Adding 'unsrt' as the bibliographystyle doesn't change anything however... Any tips on why this is the case? Here's the content of the .tex file:
\documentclass[whitelogo,table]{tu-report}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage[sort&compress,numbers]{natbib}
\usepackage{changes}
\usepackage{float}
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{dirtytalk}
\usepackage{pdfpages}
\usepackage{multirow}
\usepackage{romannum}
\usepackage[normalem]{ulem}
\useunder{\uline}{\ul}{}
\usepackage{todonotes}
\usepackage{longtable}
\usepackage{microtype}
\usepackage{wrapfig,lipsum,booktabs}
\usepackage{calc}
\usepackage{etoolbox}
\usepackage{pdfpages}
\usepackage[toc,page]{appendix}
\usepackage{etoolbox}
\apptocmd{\sloppy}{\hbadness 10000\relax}{}{}
\usepackage[utf8]{inputenc}
\usepackage[TS1,T1]{fontenc}
\usepackage{fourier, heuristica}
\usepackage{array, booktabs}
\usepackage{caption}
\usepackage[flushleft]{threeparttable}
\usepackage{outlines}
\interfootnotelinepenalty=10000 %% Completely prevent breaking of footnotes
\raggedbottom
\usepackage{rotating}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage[toc, acronym, nonumberlist]{glossaries}
\makenoidxglossaries
\bibliographystyle{unsrt}
\input{001Acronyms}
\begin{document}
\input{_01title}
\input{_02preface}
\input{_03Abstract}
\tableofcontents
\printnoidxglossaries
\mainmatter
\input{01introduction}
\input{02materialsandmethods}
\input{03results}
\input{04discussion}
\input{05conclusion}
\appendix
\input{06appendix}
\bibliography{references}
\end{document}

Typically this is caused by having citations within figure or table captions. The bad numbering is caused by the fact that the first occurrence of the citations end up being in the list of figures or the list of tables, instead of where you are expecting them to occur.
The solution is to provide a short optional caption to be used in the LOF or LOT that does not include the citation: \caption[My caption]{My caption \cite{foo}}.
However, there's no way to know for sure if this is indeed the problem without a more complete example.
See for example: https://tex.stackexchange.com/questions/552054/citation-order-is-corrupted-by-figures-and-tables

Related

Text inside of align environment

I am currently facing a small problem inside of align environment, which is the the space between words. As you can see in the following figure, the words are close to each other, and the space that is mentioned in the code, are not considered inside of align environment. I would like to know how can I solve this problem and make words more clear like the ones we tend to see in paragraphs.
enter image description here
Here is the code of the mathematic Presentation mentioned above.
\documentclass[a4paper,12pt]{report}
\usepackage[french]{babel}
\usepackage[export]{adjustbox}
\usepackage{enumitem}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage{caption}
\usepackage{booktabs, multirow}
\usepackage{soul}
\usepackage[table]{xcolor}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\begin{align*}
{\displaystyle \gamma_{b} = \quad \left\{{\begin{array}{l} 1.5 \quad (Situation Durable ou Transitoire) \\ 1.15 \quad ( Situation Accidentelle) \end{array}}\right.}
\end{align*}
\end{document}

Implementing R code in a LaTeX document with Sweave. Characters like é and è won't display correcty

I always use the bable (french) package and it works fine when one Overleaf or MiKTex. However, when copy pasting my code to Rstudio (with Sweave etc), it just does not work properly.
Document with "é" when done with Sweave
Same document (code copy pasted) on MiKTex
I have following packages:
\documentclass[a4paper, parskip=full]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage{tensor}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{enumitem}
\usepackage[abbrev,backrefs]{amsrefs}
\usepackage{appendix}
Since I don't know much about Rstudio, I don't know what information you need about it. I will provide more info when asked for.
I followed a simple tutorial on youtube to get sweave working.
Thank you.
Edit:
Here is a minimal document.
(not sure how to link the whole pdf)
The code in Rstudio (Sweave) is following:
\documentclass[a4paper, parskip=full]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage{tensor}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{enumitem}
\usepackage[abbrev,backrefs]{amsrefs}
\usepackage{appendix}
\title{Année académique}
\date{}
\begin{document}
\SweaveOpts{concordance=TRUE}
\maketitle
This is a sentence with the characters é and è.
\end{document}

Harvard citation format in R markdown

I am using R markdown for a document, however I just have to do some minor tweaks to my citations.
Firstly, is there a package which will put my BibTeX references in Harvard format?
And secondly, how can I get the author's surname and the year to be seperated by a comma within my in-text citations?
Here is one of the references in my BibTex file
#article{schwarz1978estimating,
title={Estimating the dimension of a model},
author={Schwarz, Gideon and others},
journal={The annals of statistics},
volume={6},
number={2},
pages={461--464},
year={1978},
publisher={Institute of Mathematical Statistics}
}
When I in-text reference this, it generates (Schwarz 1978). I would like a comma to seperate the surname and the year.
I've also added my YAML if that is needed
### Adding additional latex packages:
header-includes:
- \usepackage{rotating, caption} \DeclareMathOperator*{\argmin}{argmin}
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
output:
pdf_document:
keep_tex: yes
template: Tex/TexDefault.txt
fig_width: 3.5 # Adjust default figure sizes. This can also be done in the chunks of the text.
fig_height: 3.5
I rely on the standard (and very powerful) natbib package which many Rmd styles already add, and which you can generally add to whichever RMarkdown template you use (and you didn't say).
Quick example using my pinp package:
---
title: Example
author:
- name: Dirk Eddelbuettel
affiliation: a
address:
- code: a
address: Planet Earth
papersize: letter
fontsize: 12pt
one_column: true
bibliography: ref
output: pinp::pinp
---
# Introduction
Two quick examples using natbib
- citet: \citet{schwarz1978estimating}
- citep: \citep{schwarz1978estimating}
For the rest, see the natbib documentation, either at source or contributed
such as https://gking.harvard.edu/files/natnotes2.pdf.
The body of that document comes out as follows:

R markdown with Beamer: table too wide

I've been trying for ages to find a way to get my table to shrink enough to fit on a slide. The base code looks like:
---
title: "Untitled"
output: beamer_presentation
---
```{r setup, include = FALSE}
library(knitr)
library(kableExtra)
```
## Table
The table below is too long.
```{r}
kable(summary(mtcars), format = "latex")
```
If I try adding %>% kable_styling(full_width = TRUE) or anything like that, I get this error:
! LaTeX Error: Environment tabu undefined.. But I don't get it when I change the output to pdf_document.
Is there anyway to make tables that are too wide fit into a beamer presentation? Or will I always be limited to about 5/6 columns?
For your specific task, I think you should use `kable_styling(latex_options = "scale_down").
===
If you want to use other features in kableExtra, put the following things in your yaml header. You can find some extra explanation at the very beginning (on Page 2 right now) of the package manual(http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf).
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}

RMarkdown and YAML not able to load packages

I have a text that I want to convert from latex to Markdown for various reasons. But I'm not able to make it work. If I load all the packages and only type "yo" as text, it's returning me an error.
Error in yaml::yaml.load(enc2utf8(string), ...) :
Scanner error: while scanning a directive at line 5, column 1could not find expected directive name at line 5, column 2
Calls: <Anonymous> ... yaml_load_utf8 -> mark_utf8 -> <Anonymous> -> .Call
Execution halted
Many people had this error before but I haven't saw somebody encountering this error so far and a solution for packages like this.
Can we write comments "%" in the preamble?
How can I add my latex packages in RMarkdown?
Will it work if I export it in word?
Here is my code:
---
title: "rest"
author: "Me"
date: '2016-10-26'
header-includes:
% Titles
- \usepackage{titlesec}
% figure
- \usepackage{color}
- \usepackage{graphicx} % Enhanced support for graphics
- \usepackage{subfig} % subfigure environment
- \usepackage{float} % Improved interface for floating objects
- \usepackage{rotating} % Rotation tools, including rotated full-page floats
% \usepackage[labelfont=bf]{caption} % Customising captions in floating environments
% tables
- \usepackage[table]{xcolor} % Driver-independent color extensions
- \usepackage{array} % Extending the array and tabular environments
- \usepackage{longtable} % Allow tables to flow over page boundaries
- \usepackage{multirow} % Create tabular cells spanning multiple rows
% math
- \usepackage{amssymb} % some weird math symbols
- \usepackage{amsthm}
- \usepackage{amsmath} % AMS mathematical facilities for LATEX
% documents aspect
- \usepackage{lineno} % Line numbers on paragraphs
- \usepackage[top=2.2cm, left=2.2cm,right=2.2cm,bottom=4.2cm]{geometry} % Flexible and complete interface to document d=imensions
% see geometry.pdf on how to lay out the page. There's lots.
- \usepackage[utf8]{inputenc} % Accept different input encodings
- \usepackage[T1]{fontenc}
- \usepackage{lscape} % Place selected parts of a document in landscape
- \usepackage{babel}
% reference in text
- \usepackage[unicode=true, pdfusetitle, bookmarks=true, bookmarksnumbered=false, bookmarksopen=false, breaklinks=true, pdfborder={0 0 0}, backref=page,colorlinks=true]
{hyperref}
- \newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}}
% bibliography
%\usepackage[style=authoryear, backend=bibtex,bibencoding=ascii]{biblatex} % Bibliographies in LATEX using BibTEX for sorting only
- \usepackage{natbib} % Flexible bibliography support
% \usepackage{translation-natbib-fr} %French translation of the documentation of natbib
%\renewbibmacro{in:}{}
%\bibliography{yo.bib}
% \ref{} makes reference to a \label{} set in a table or figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
- \theoremstyle{plain}
title: "data"
author: "Me"
date: '2016-10-26'
output:
pdf_document: default
word_document: default
documentclass: article % - \documentclass[english]{scrartcl
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
YO
Your header contains invalid YAML, inline comments need #:
---
title: "rest"
author: "Me"
date: '2016-10-26'
header-includes:
# Titles
- \usepackage{titlesec}
# figure
- \usepackage{color}
- \usepackage{graphicx}
...
You'll also need to de-duplicate your YAML map keys. Sure, you can render RMarkdown to Word with the obvious caveat that LaTeX-specific formatting won't automagically carry over.

Resources