latex - papaja 生成的 Rmarkdown 中使用 ragged2e 进行文本对齐

标签 latex r-markdown papaja

我一直在尝试使用“ragged2e”在 papaja 生成的文档中使用此处提出的方法进行文本对齐:

https://stackoverflow.com/a/50042106

但是,当我尝试编织这个时:

---
title             : "My title"
shorttitle        : "Title"

author: 
  - name          : "Raphaël Lorenz-de Laigue"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Postal address"
    email         : "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a27330a2f272b232664292527" rel="noreferrer noopener nofollow">[email protected]</a>"

affiliation:
  - id            : "1"
    institution   : "Humboldt-Universität zu Berlin"

abstract: This is my abstract.
keywords          : "keywords"
wordcount         : "X"

floatsintext      : no
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : no
mask              : no
draft             : no
figsintext        : yes
header-includes:
   - \usepackage[document]{ragged2e}
documentclass     : "apa6"
classoption       : "man"
output:
  papaja::apa6_pdf:
    latex_engine: xelatex
    fig_caption: yes
---
```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```
\justify

# Intro
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Commodo quis imperdiet massa tincidunt. Magna fermentum iaculis eu non diam phasellus vestibulum lorem. Ultricies integer quis auctor elit sed vulputate mi. Ligula ullamcorper malesuada proin libero nunc. Viverra justo nec ultrices dui sapien. Quisque egestas diam in arcu cursus euismod quis viverra. Suspendisse potenti nullam ac tortor vitae purus faucibus. Massa sapien faucibus et molestie ac. Volutpat commodo sed egestas egestas fringilla phasellus. Nibh cras pulvinar mattis nunc sed blandit libero volutpat. Ullamcorper morbi tincidunt ornare massa eget egestas purus viverra. Eu facilisis sed odio morbi quis. In aliquam sem fringilla ut morbi tincidunt augue. Dictumst quisque sagittis purus sit amet volutpat consequat mauris. Nec feugiat nisl pretium fusce. Sed euismod nisi porta lorem mollis aliquam ut porttitor. Ut enim blandit volutpat maecenas volutpat. Consectetur lorem donec massa sapien. Urna neque viverra justo nec.

我收到以下错误消息:

I was unable to find any missing LaTeX packages from the error log not_justified.log.
! Improper \prevdepth.
\newpage ...everypar {}\fi \par \ifdim \prevdepth 
                                                  >\z@ \vskip -\ifdim \prevd...
l.190 \end{document}

Error: LaTeX failed to compile not_justified.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See not_justified.log for more info.
In addition: Warning message:
In readLines(con, encoding = "bytes") :
  incomplete final line found on 'justified.Rmd'
Execution halted

我尝试更新 R 和 LaTeX 软件包,重新安装 tinytex,如下所示: https://yihui.org/tinytex/r/#debugging

代码包含“tinytex.verbose”选项,如上所示。

最好,

R。

编辑:

这是中间 .tex 文件的内容

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
  man,floatsintext]{apa6}
\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={My title},
  pdfauthor={Raphaël Lorenz-de Laigue1},
  pdflang={en-EN},
  pdfkeywords={keywords},
  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
\ifLuaTeX
\usepackage[bidi=basic]{babel}
\else
\usepackage[bidi=default]{babel}
\fi
\babelprovide[main,import]{english}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
% 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}\centering\begin{threeparttable}}
%   {\end{threeparttable}\end{landscape}}
\newenvironment{lltable}{\begin{landscape}\centering\begin{ThreePartTable}}{\end{ThreePartTable}\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}
\keywords{keywords\newline\indent Word count: X}
\DeclareDelayedFloatFlavor{ThreePartTable}{table}
\DeclareDelayedFloatFlavor{lltable}{table}
\DeclareDelayedFloatFlavor*{longtable}{table}
\makeatletter
\renewcommand{\efloat@iwrite}[1]{\immediate\expandafter\protected@write\csname efloat@post#1\endcsname{}}
\makeatother
\usepackage{csquotes}
\usepackage[document]{ragged2e}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi

\title{My title}
\author{Raphaël Lorenz-de Laigue\textsuperscript{1}}
\date{}


\shorttitle{Title}

\authornote{

Correspondence concerning this article should be addressed to Raphaël Lorenz-de Laigue, Postal address. E-mail: \href{mailto:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="711c0831141c10181d5f121e1c" rel="noreferrer noopener nofollow">[email protected]</a>}{\nolinkurl{<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315c4871545c50585d1f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>}}

}

\affiliation{\vspace{0.5cm}\textsuperscript{1} Humboldt-Universität zu Berlin}

\abstract{%
This is my abstract.
}



\begin{document}
\maketitle

\justify

\hypertarget{intro}{%
\section{Intro}\label{intro}}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Commodo quis imperdiet massa tincidunt. Magna fermentum iaculis eu non diam phasellus vestibulum lorem. Ultricies integer quis auctor elit sed vulputate mi. Ligula ullamcorper malesuada proin libero nunc. Viverra justo nec ultrices dui sapien. Quisque egestas diam in arcu cursus euismod quis viverra. Suspendisse potenti nullam ac tortor vitae purus faucibus. Massa sapien faucibus et molestie ac. Volutpat commodo sed egestas egestas fringilla phasellus. Nibh cras pulvinar mattis nunc sed blandit libero volutpat. Ullamcorper morbi tincidunt ornare massa eget egestas purus viverra. Eu facilisis sed odio morbi quis. In aliquam sem fringilla ut morbi tincidunt augue. Dictumst quisque sagittis purus sit amet volutpat consequat mauris. Nec feugiat nisl pretium fusce. Sed euismod nisi porta lorem mollis aliquam ut porttitor. Ut enim blandit volutpat maecenas volutpat. Consectetur lorem donec massa sapien. Urna neque viverra justo nec.


\end{document}

最佳答案

justify 不是一个宏,而是一个环境。此环境旨在用作 \begin{justify} ...\end{justify}

就您而言,如果您仍想在其中使用 markdown,则可能不需要环境。所以你可以使用宏 \justifying 来代替:

---
title             : "My title"
shorttitle        : "Title"

author: 
  - name          : "Raphaël Lorenz-de Laigue"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Postal address"
    email         : "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="422f3b02272f232b2e6c212d2f" rel="noreferrer noopener nofollow">[email protected]</a>"

affiliation:
  - id            : "1"
    institution   : "Humboldt-Universität zu Berlin"

abstract: This is my abstract.
keywords          : "keywords"
wordcount         : "X"

floatsintext      : no
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : no
mask              : no
draft             : no
figsintext        : yes
header-includes:
   - \usepackage[document]{ragged2e}
documentclass     : "apa6"
classoption       : "man"
output:
  papaja::apa6_pdf:
    latex_engine: xelatex
    fig_caption: yes
---
```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```
\justifying

# Intro
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Commodo quis imperdiet massa tincidunt. Magna fermentum iaculis eu non diam phasellus vestibulum lorem. Ultricies integer quis auctor elit sed vulputate mi. Ligula ullamcorper malesuada proin libero nunc. Viverra justo nec ultrices dui sapien. Quisque egestas diam in arcu cursus euismod quis viverra. Suspendisse potenti nullam ac tortor vitae purus faucibus. Massa sapien faucibus et molestie ac. Volutpat commodo sed egestas egestas fringilla phasellus. Nibh cras pulvinar mattis nunc sed blandit libero volutpat. Ullamcorper morbi tincidunt ornare massa eget egestas purus viverra. Eu facilisis sed odio morbi quis. In aliquam sem fringilla ut morbi tincidunt augue. Dictumst quisque sagittis purus sit amet volutpat consequat mauris. Nec feugiat nisl pretium fusce. Sed euismod nisi porta lorem mollis aliquam ut porttitor. Ut enim blandit volutpat maecenas volutpat. Consectetur lorem donec massa sapien. Urna neque viverra justo nec.

关于latex - papaja 生成的 Rmarkdown 中使用 ragged2e 进行文本对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72430587/

相关文章:

papaja - 无法编织 papaja 文件 - 已弃用 pandoc-citeproc 过滤器

r - latex 错误 : Environment ThreePartTable undefined

r 表列出多个具有频率的分类变量

Rmarkdown删除引用超链接

python - 如何要求 sympy 不要将 bm 翻译成 boldsymbol?

r - 记录 with\code{\link[package] 时,避免在 pdf 中出现指向任何地方的链接

latex - 在 R Markdown 中渲染 Angstrom

latex - 在 Latex 中隐藏 Toc 的条目

r - tools::texi2dvi - 它发生了什么事?

r - 在外部 LaTeX 文件中将 YAML 参数作为宏访问