![段落の終わりに影響を与えずにフォントサイズを変更するときに行間隔を修正する](https://rvso.com/image/472698/%E6%AE%B5%E8%90%BD%E3%81%AE%E7%B5%82%E3%82%8F%E3%82%8A%E3%81%AB%E5%BD%B1%E9%9F%BF%E3%82%92%E4%B8%8E%E3%81%88%E3%81%9A%E3%81%AB%E3%83%95%E3%82%A9%E3%83%B3%E3%83%88%E3%82%B5%E3%82%A4%E3%82%BA%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B%E3%81%A8%E3%81%8D%E3%81%AB%E8%A1%8C%E9%96%93%E9%9A%94%E3%82%92%E4%BF%AE%E6%AD%A3%E3%81%99%E3%82%8B.png)
次のコードを考えてみましょう。
\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
\lipsum[1]%
\begingroup%
\tiny\color{red}%
\lipsum[2]%
\endgroup%
\lipsum[3]%
\end{document}
次の出力が生成されます。
私が抱えている問題は、テキストの小さな部分の行間隔を再計算したいということです。これを実現するには、\par
グループに を追加することです。
\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
\lipsum[1]%
\begingroup%
\tiny\color{red}%
\lipsum[2]%
\par%
\endgroup%
\lipsum[3]%
\end{document}
これにより、次のものが生成されます。
どちらが良いかはわかりませんが、同じ段落内に留まり、改行を避けたいと考えています。
質問:段落の終わりや改行を起こさずに、小さなフォントで書かれたテキストの行間を狭くするにはどうすればよいでしょうか? (どのフォント サイズにも対応できるソリューションを希望します)。
答え1
小さなテキストの終了位置を記録し、その位置に戻って大きなテキストを開始することができます。これには 2 回の実行が必要です。
\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\makeatletter
\begingroup%
\tiny\color{red}%
aaa \lipsum[2]%
{\normalsize\strut}%
\pdfsavepos\write\@auxout{\gdef\string\wdA{\the\pdflastxpos}}
\par%
\endgroup
\nopagebreak\kern-\baselineskip
\noindent\pdfsavepos\write\@auxout{\gdef\string\wdB{\the\pdflastxpos}}
\ifx\wdA\undefined\else
\kern\numexpr\wdA-\wdB\relax sp\fi
\lipsum[3]%
\end{document}