
各サブセクションに右揃えの2行(ある種の「ページメタデータ」)を配置したい。それらの行は一度もない全幅になります (1 つには日付のみが含まれます)。
そのために、私は、(1)「Underfull hbox」警告をすべて回避し、(2)それほど多くの入力をせずに済むように、それらを RaggedLeft 環境に配置するコマンドを定義しようとしていました。
それは機能しません。
% !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}
その結果、2 行目は左にバインドされ、依然として「underfull hbox」警告が表示されます。
面白い事実: これを環境に配置すると\FlushRight
動作しますが、これは (1) 私が望んでいることではない、(2) 警告がまだ表示される、(3) まったく理解できない、そして理解できないものは好きではない ;) です。
ragged2e 以外のコマンドを使用した実験でも同じ結果が得られます。
私はMacでlatexmk(luatex 1.10.0 / TeX live 2019付き)を使用しています。
答え1
実際には、\end{RaggedLeft}
右揃えのタイプセットは終了するだけですが、段落終了コマンドは発行されないため、2 行目は標準設定でタイプセットされます。
あなたの場合、\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}