I'm creating an R Markdown document using the 'papaja' package and the 'apa7' LaTeX template. When used together, the latter package and template currently produce a conflict due to duplicated \author and \affiliation fields in the tex file. Earlier, a method was found to resolve this conflict that worked by adding the following LaTeX commands to the preamble (through header-includes in the YAML header):
- \renewcommand\author[1]{}
- \renewcommand\affiliation[1]{}
However, this method is not currently working (I couldn't find out why). I've tried several modifications of the above code, such as \renewcommand\author{\phantom{}}{}, but to no avail.
The error can be reproduced with the following steps:
In RStudio, install the development version of the papaja package:
# Install devtools package if necessary
if(!"devtools" %in% rownames(installed.packages())) install.packages("devtools")
# Install the stable development verions from GitHub
devtools::install_github("crsh/papaja")
Click on the + button at the top left and create an R Markdown document.
Delete all the content in the new file and replace it with the following:
---
title : "Long title"
shorttitle : "Short title"
documentclass : apa7
classoption : man
output : papaja::apa6_pdf
header-includes:
- \authorsnames[1, 2, 2]{first author, second author, third author}
- \authorsaffiliations{{first affiliation}, {second affiliation}}
---
text text text text text text text text text.
Knit the document.
Notice the following error in the console:
! LaTeX Error: Command \c#NumberOfAuthors already defined.
Or name \end... illegal, see p.192 of the manual.
Error: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.
Execution halted
Open the .tex file that has been produced, delete the two lines containing \author{\phantom{0}} and \affiliation{\phantom{0}}, and hit the Compile PDF button. Notice that the document is now knitted well.
For a single individual, the above workaround using the tex file might not be too problematic. However, it proves problematic for the reproducibility of the manuscript by other people.
I would be sincerely grateful if someone could suggest a solution based on some LaTex code entered in the header-includes preamble.
Thank you very much!
.tex file
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
english,
man]{apa7}
\title{Long title}
\author{\phantom{0}}
\date{}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\#ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Long title},
pdflang={en-EN},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin#nat#width>\linewidth\linewidth\else\Gin#nat#width\fi}
\def\maxheight{\ifdim\Gin#nat#height>\textheight\textheight\else\Gin#nat#height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps#figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
% Manuscript styling
\usepackage{upgreek}
\captionsetup{font=singlespacing,justification=justified}
% Table formatting
\usepackage{longtable}
\usepackage{lscape}
% \usepackage[counterclockwise]{rotating} % Landscape page setup for large tables
\usepackage{multirow} % Table styling
\usepackage{tabularx} % Control Column width
\usepackage[flushleft]{threeparttable} % Allows for three part tables with a specified notes section
\usepackage{threeparttablex} % Lets threeparttable work with longtable
% Create new environments so endfloat can handle them
% \newenvironment{ltable}
% {\begin{landscape}\begin{center}\begin{threeparttable}}
% {\end{threeparttable}\end{center}\end{landscape}}
\newenvironment{lltable}{\begin{landscape}\begin{center}\begin{ThreePartTable}}{\end{ThreePartTable}\end{center}\end{landscape}}
% Enables adjusting longtable caption width to table width
% Solution found at http://golatex.de/longtable-mit-caption-so-breit-wie-die-tabelle-t15767.html
\makeatletter
\newcommand\LastLTentrywidth{1em}
\newlength\longtablewidth
\setlength{\longtablewidth}{1in}
\newcommand{\getlongtablewidth}{\begingroup \ifcsname LT#\roman{LT#tables}\endcsname \global\longtablewidth=0pt \renewcommand{\LT#entry}[2]{\global\advance\longtablewidth by ##2\relax\gdef\LastLTentrywidth{##2}}\#nameuse{LT#\roman{LT#tables}} \fi \endgroup}
% \setlength{\parindent}{0.5in}
% \setlength{\parskip}{0pt plus 0pt minus 0pt}
% Overwrite redefinition of paragraph and subparagraph by the default LaTeX template
% See https://github.com/crsh/papaja/issues/292
\makeatletter
\renewcommand{\paragraph}{\#startsection{paragraph}{4}{\parindent}%
{0\baselineskip \#plus 0.2ex \#minus 0.2ex}%
{-1em}%
{\normalfont\normalsize\bfseries\itshape\typesectitle}}
\renewcommand{\subparagraph}[1]{\#startsection{subparagraph}{5}{1em}%
{0\baselineskip \#plus 0.2ex \#minus 0.2ex}%
{-\z#\relax}%
{\normalfont\normalsize\itshape\hspace{\parindent}{#1}\textit{\addperi}}{\relax}}
\makeatother
% \usepackage{etoolbox}
\makeatletter
\patchcmd{\HyOrg#maketitle}
{\section{\normalfont\normalsize\abstractname}}
{\section*{\normalfont\normalsize\abstractname}}
{}{\typeout{Failed to patch abstract.}}
\patchcmd{\HyOrg#maketitle}
{\section{\protect\normalfont{\#title}}}
{\section*{\protect\normalfont{\#title}}}
{}{\typeout{Failed to patch title.}}
\makeatother
\usepackage{xpatch}
\makeatletter
\xapptocmd\appendix
{\xapptocmd\section
{\addcontentsline{toc}{section}{\appendixname\ifoneappendix\else~\theappendix\fi\\: #1}}
{}{\InnerPatchFailed}%
}
{}{\PatchFailed}
\usepackage{csquotes}
\authorsnames[1, 2, 2]{first author, second author, third author}
\authorsaffiliations{{first affiliation}, {second affiliation}}
\ifXeTeX
% Load polyglossia as late as possible: uses bidi with RTL langages (e.g. Hebrew, Arabic)
\usepackage{polyglossia}
\setmainlanguage[]{english}
\else
\usepackage[main=english]{babel}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
\fi
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\shorttitle{Short title}
\affiliation{\phantom{0}}
\begin{document}
\maketitle
text text text text text text text text text.
\end{document}
Quick hack:
---
title : "Long title"
shorttitle : "Short title"
documentclass : apa7
classoption : man
output : papaja::apa6_pdf
header-includes:
- \xpatchcmd{\authorsnames}{\newcounter{NumberOfAuthors}}{\setcounter{NumberOfAuthors}{0}}{}{}
- \xpatchcmd{\authorsnames}{\newcounter{NumberOfSuperscripts}}{\setcounter{NumberOfSuperscripts}{0}}{}{}
- \authorsnames[1, 2, 2]{first author, second author, third author}
- \authorsaffiliations{{first affiliation}, {second affiliation}}
- \renewcommand{\affiliation}[1]{}
---
text text text text text text text text text.
I found a book on the Papaja package. That link will bring you to the YAML section. I think this is what you were looking for.
First, there doesn't appear to be an association for APA 7, unless you have the development version of Papaja. That being said, there is a ticket on this in their main github.
If you set the output to apa6_docx, this "and &" error won't be there. (And even if it were, you could have deleted it.) You can save it as a PDF from there. I'm not sure if this is an option for you, but I thought I would mention it.
This is what it states about subsequent authors (and much more).
---
title : "Long title"
shorttitle : "Short title"
author:
- name : "First Author"
affiliation : "1"
- name : "Second Author"
affiliation : "1"
- name : "Third Author"
affiliation : "2"
affiliation:
- id : "1"
institution : "The University"
- id : "2"
institution : "The Other University"
documentclass : apa7
classoption : man
output : papaja::apa6_docx
---
text text text text text text text text text.
Related
I cannot get Biber to run on a file where I \input multiple .tex files in the root file. If I were to run a MWE like so
% !TeX TXS-program:bibliography = txs:///biber
\documentclass[a4paper,style=index]{book}
\usepackage[T1,LGR,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,russian,main=british]{babel} % Compile w/PDFLaTeX !!!!!
\languageattribute{greek}{ancient}
\usepackage{cjhebrew}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm,columnsep=30pt]{geometry} % Document margins and spacings
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{epigraph}
\usepackage{csquotes}
\usepackage[style=apa, backend=biber, useprefix=false]{biblatex}
\AtEveryCitekey{\toggletrue{blx#useprefix}}
\setlength\bibitemsep{\baselineskip}
\bibliography{references.bib}
\addbibresource{references.bib}
\usepackage{fancyhdr} % Required for modifying headers and footers
\fancyhead[L]{\rightmark} % Top left header
\fancyhead[R]{\leftmark} % Top right header
\renewcommand{\headrulewidth}{0pt} % Rule under the header
\fancyfoot[C]{\textbf{\thepage}} % Bottom center footer
\renewcommand{\footrulewidth}{0pt} % Rule under the footer
% Use the custom headers and footers throughout the document
\usepackage{xcolor}
\usepackage[linktoc=all, colorlinks]{hyperref}
\usepackage[acronyms,nopostdot]{glossaries} % allows glossaries
\input{glossaries}
\makeglossaries
\begin{document}
This is a sentence with an \acrfull{acronym} \parencite{bellbottom}.
\end{document}
having defined \newacronym{acronym}{acr}{acronym} (separate .tex) and #book{bellbottom,author= ...} (in a .bib file), everything goes well.
If the last part looks like you'd expect in a bigger document, however, like so
\begin{document}
\input{intro.tex}
\printbibliography
\printglossary
\end{document}
the rendered PDF shows a bold citekey in parentheses. This excellent guide tells me to look for a .blg file, which I do not get with the \input example.
I compile: pdfLaTex → makeglossaries → biber → pdfLaTex → pdfLaTeX. I'm working with VS Code (1.71.2) and MikTeX (22.8.28).
{
"name": "biber",
"command": "biber",
"args": [
"%DOCFILE%"
],
"env": {}
}
Have any of you had similar issues?
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{banking}
\moderncvcolor{blue}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{import}
% links Symbol
\usepackage{bbding,pifont}
\usepackage[hidelinks]{hyperref}
% Redefinition:
\let\orighref\href
\newcommand{\hrefa}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{...code}{#1}}
\newcommand{\hrefb}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{xxx/}{#1}}
\newcommand{\hrefc}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{ccc}{#1}}
\newcommand{\hrefd}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{vvv/}{#1}}
\newcommand{\hrefe}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{vvv}{#1}}
\newcommand{\hreff}[1]{\raisebox{-0.4ex}{\HandRight}\,\orighref{vvv}{#1}}
% end links symbol
% personal data
\name{...}
\title{}
\address{..}{}{}
\phone[mobile]{+...4}
\email{xxx#a.com}
\extrainfo{\hrefd{xc.com}}
%\photo[64pt][0.4pt]{photo.jpg}
%----------------------------------------------------------------------------------
% content
%----------------------------------------------------------------------------------
\begin{document}
Error:
LaTeX Error: Option clash for package hyperref.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.40 \begin{document}
The package hyperref has already been loaded with options:
[hidelinks]
There has now been an attempt to load it with options
[unicode]
Adding the global options:
hidelinks,unicode
to your \documentclass declaration may fix this.
Try typing <return> to proceed.
when i try to convert to pdf, i get an empty html file.
The moderncv class automatically loads the hyperref package. You can use \PassOptionsToPackage{hidelinks}{hyperref} to make sure it is loaded with the options you want.
(although your hidelinks option won't make a big difference because moderncv sets the line width of the link boxes to zero, so they are already invisible)
\PassOptionsToPackage{hidelinks}{hyperref}
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{banking}
\moderncvcolor{blue}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{import}
% links Symbol
\usepackage{bbding,pifont}
% personal data
\name{...}
\title{}
\address{..}{}{}
\phone[mobile]{+...4}
\email{xxx#a.com}
%\extrainfo{\hrefd{xc.com}}
%\photo[64pt][0.4pt]{photo.jpg}
%----------------------------------------------------------------------------------
% content
%----------------------------------------------------------------------------------
\begin{document}
test
\url{stackoverflow.com}
\end{document}
I am using the Ph.D. dissertation .cls file. When I create a paragraph there is a misalignment in the paragraph page number in TOC.
Below is the minimal code:
\documentclass[final]{USC-Thesis_Minimal}
\usepackage[lofdepth,lotdepth,caption=false]{subfig}
\begin{document}
\title{Some title}
\author{Some Name}
\major{Some Engineering}
\month{May}
\year{2019}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\maketitle
% Table Of Contents
\cleardoublepage\phantomsection
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents
% List of tables
\listoftables
% List of figures
\listoffigures
% Begin Body
\mainmatter
\chapter{Chapter 1}
\section{A very long section, very long text section}
\subsection{A very long subsection, very long text subsection}
\subsubsection{A very long subsubsection Very long text subsubsection}
\paragraph{A long paragraph}
\end{document}
Below is the relevant part of the cls file.
%Margins of Table of Contents - so that the page listings for toc do
%not align with page number
\cftsetrmarg{0.7in}
\newlength{\numtomarg}
\setlength{\numtomarg}{0.2in}
\renewcommand{\cftchapafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsecafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubsecafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubsubsecafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftfigafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubfigafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cfttabafterpnum}{\hspace{\numtomarg}\mbox{}}
\renewcommand{\cftsubtabafterpnum}{\hspace{\numtomarg}\mbox{}}
I couldn't find an alternative for the paragraph. Similar to:
\renewcommand{\cftparagraphafterpnum}{\hspace{\numtomarg}\mbox{}}
Here is the link to the class file. Can somebody please help me to fix this issue?
Using the below LaTeX command did the trick:
\renewcommand{\cftparaafterpnum}{\hspace{\numtomarg}\mbox{}}
I am trying to get my document parts to show up as:
A. Narrative % \part{Narrative}
Intro %\section{Intro}
main text...
B. Appendix % \part{Appendix}
Derivations % \section{Derivations}
appendix text...
I have seen others use:
\renewcommand{\thepart}{\Alph{part}}
However this is not working for me for some reason. My parts are showing up as:
Part A
Narrative
Intro
main text...
Part B
Appendix
Derivations
appendix text...
Any ideas anyone?
The minimal example below updates \part to set its numbering differently. More specifically, it removes the \partname - Part - prefix and keeps the title on the same line. Fonts are also updated to set the part using \LARGE\bfseries in both \part and \part*. All of the above updates are done using etoolbox's \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} macro that performs a <search>-and-<replace> within <cmd>.
\documentclass{article}
\usepackage{lipsum,etoolbox}
\renewcommand{\thepart}{\Alph{part}}
\makeatletter
% Change part display; also uniform size of \LARGE\bfseries
\patchcmd{\#part}% <cmd>
{\Large\bfseries \partname\nobreakspace\thepart \par\nobreak}% <search>
{\LARGE\bfseries \thepart.\quad}% <replace>
{}{}% <success><failure>
\patchcmd{\#part}{\huge}{\LARGE}{}{}
\patchcmd{\#spart}{\huge}{\LARGE}{}{}
\renewcommand{\#seccntformat}[1]{\csname the#1\endcsname.\quad}
% \#addtoreset{section}{part} % Reset section counter with every part
\makeatother
\begin{document}
\part{Narrative}
\section{Intro}
\lipsum[1]
\part{Appendix}
\section{Derivations}
\lipsum[2]
\end{document}
If you wish to have the \section numbers reset with every new \part, uncomment the line referencing that in the preamble.
Your idea is right, but you also redefine the titleformat.
From the following link:
\usepackage{titlesec}
\renewcommand{\thepart}{\Alph{part}}
\makeatletter
\titleformat{\part}[display]
{\Huge\scshape\filright}
{\thepart~\partname}
{20pt}
{\thispagestyle{plain}}
\makeatother
I've seen a pdf LaTeX document where the page numbers at the bottom of the page are hyperref links, and clicking them causes you to jump to the contents table. I don't have the tex file and couldn't work out how it's done from the hyperref package. Can anyone help?
You could set an anchor at the toc and redefine \thepage to link to it. Here's an example:
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
\renewcommand*{\thepage}{\hyperref[contents]{\arabic{page}}}
\begin{document}
\tableofcontents
\chapter{One}
Text
\end{document}
If you use babel and wish to redefine \contentsname, use the \addto command of babel or redefine \contentsname after \begin{document}.
Have you tried defining the page numbering using this?
\pagestyle{myheadings}
\markright{ ... }
where \markright specifies the page number with a link to the content page.
Here is how I did it
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts
\usepackage{hyperref}
\usepackage[pagestyles]{titlesec}
\newpagestyle{article}{
\setfoot
%% even pages
[]
[\footnotesize \hyperlink{toc}{\thepage}]
[]
%% odd pages
{}
{\footnotesize \hyperlink{toc}{\thepage}}
{}
}
\begin{document}
\title{example}
\date{}
\author{author}
\maketitle
\pagenumbering{roman}
\setcounter{tocdepth}{2}
\addtocontents{toc}{\protect\hypertarget{toc}{}}
\tableofcontents
\newpage
\pagenumbering{arabic}
\pagestyle{article}
\section{A}
\lipsum[1]
\subsection{a}
\lipsum[2]
\subsection{b}
\lipsum[3]
\subsection{c}
\lipsum[4]
\section{B}
\lipsum[5]
\subsection{d}
\lipsum[6]
\subsection{e}
\lipsum[7]
\section{C}
\lipsum[8]
\subsection{f}
\lipsum[9]
\subsection{g}
\lipsum[10]
\subsection{h}
\lipsum[11]
\end{document}
you can of course customize the link text back to table of contents however you like in the preamble, please read documentation of titlesec for more details.