簡體   English   中英

在 papaja 生成的 Rmarkdown 中使用 ragged2e 進行文本對齊

[英]Text justification with ragged2e inside a papaja-generated Rmarkdown

我一直在嘗試使用此處提出的方法在 papaja 生成的文檔中使用“ragged2e”進行文本對齊:

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         : "my@email.com"

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:my@email.com}{\nolinkurl{my@email.com}}

}

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

在您的情況下,如果您仍想在其中使用降價,則可能不需要環境。 所以你可以使用宏\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         : "my@email.com"

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.

暫無
暫無

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

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