\newcommand 中的 \RaggedLeft 未如預期運作

\newcommand 中的 \RaggedLeft 未如預期運作

我想在每個小節上右對齊有兩行(某種「頁面元資料」)。這些線是絕不將是全角(其中僅包含日期)。

為此,我試圖定義一個命令,將它們放入 RaggedLeft 環境中,以 (1) 避免所有這些「Underfull hbox」警告,以及 (2) 不要輸入太多內容。

它就是行不通。

% !TEX root = ./raggedleft.tex

\documentclass{article}

\usepackage[english,ngerman]{babel}
\usepackage[hidelinks]{hyperref}
\usepackage{lmodern,textcomp}
\usepackage{ifluatex}
\ifluatex
  \usepackage{luacode}
  \usepackage{fourier}
  \usepackage{fontspec}
  \setmainfont{Erewhon}
\else
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{fourier}
\fi
\usepackage[document]{ragged2e}

\setlength{\parskip}{1em}
\setlength{\parindent}{3em}
\renewcommand{\baselinestretch}{1.2}

%% new command: \postheader{datestring}{tagstring}
%% prints the post date and tags right-aligned
\newcommand\postheader[2]{%
  \begin{RaggedLeft}%
  #1\\#2%
  \end{RaggedLeft}%
}


\begin{document}

\postheader{Some weird words on the right}{and more words, hopefully right-bound}

Normal boring left-aligned text.

\end{document}

結果是第二行是左綁定的,我仍然收到“underfull hbox”警告。

有趣的事實:如果我將其放置在\FlushRight它可以工作的環境中,但這(1)不是我想要的,(2)我仍然收到警告,(3)我根本不理解它,而且我不'不喜歡我不理解的東西;)。

使用非 ragged2e 指令進行的實驗會產生相同的結果。

我在 Mac 上使用 Latexmk (帶有 luatex 1.10.0 / TeX live 2019)。

答案1

發生的情況是\end{RaggedLeft}簡單地結束右對齊排版,但不發出段落結束命令,因此第二行使用標準設定進行排版。

在你的情況下,\RaggedLeft這不是正確的工具,因為使用短線你會得到未滿的盒子。使用標準\raggedleft聲明。

我透過刪除所有不重要的位元來最小化這個範例。

\documentclass{article}

%% new command: \postheader{datestring}{tagstring}
%% prints the post date and tags right-aligned
\newcommand\postheader[2]{%
  \par\begingroup\raggedleft #1\\#2\\\endgroup
}


\begin{document}

\postheader{Some weird words on the right}{and more words, hopefully right-bound}

Normal boring left-aligned text.

\end{document}

在此輸入影像描述

相關內容