簡體   English   中英

刪除 R papaja 文檔中多余的 `\author` 和 `\affiliation` 字段

[英]Deleting redundant `\author` and `\affiliation` fields in R papaja document

I'm creating an R Markdown document using the 'papaja' package and the 'apa7' LaTeX template. 當一起使用時,后者 package 和模板當前會由於tex文件中重復的\author\affiliation字段而產生沖突。 早些時候,發現了一種解決此沖突的方法,該方法通過將以下 LaTeX 命令添加到前導碼中(通過 YAML 標頭中的標header-includes ):

  - \renewcommand\author[1]{}
  - \renewcommand\affiliation[1]{}

但是,這種方法目前不起作用(我找不到原因)。 我已嘗試對上述代碼進行多次修改,例如\renewcommand\author{\phantom{}}{} ,但無濟於事。

可以通過以下步驟重現該錯誤:

  1. 在RStudio中,安裝開發版的木瓜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")
  2. 單擊左上角的+按鈕並創建R Markdown文檔。

  3. 刪除新文件中的所有內容並將其替換為以下內容:

     --- 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.
  4. 編織文件。

  5. 請注意控制台中的以下錯誤:

     : 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
  6. 打開已經生成的.tex文件,刪除包含\author{\phantom{0}}\affiliation{\phantom{0}}的兩行,然后點擊Compile PDF按鈕。 請注意,文檔現在編織得很好。

對於單個人,上述使用tex文件的解決方法可能不會有太大問題。 然而,它證明了其他人手稿的可重復性存在問題。

如果有人可以根據在header-includes序言中輸入的一些 LaTex 代碼提出解決方案,我將不勝感激。

非常感謝!



.tex文件

% 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}

我找到了一本關於Papaja package的書。 該鏈接會將您帶到 YAML 部分。 我想這就是你要找的。

這就是它對后續作者(以及更多)的陳述。

---
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_pdf
---

text text text text text text text text text.

在此處輸入圖像描述

快速破解:

---
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.

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM