如何对齐单词?

如何对齐单词?

我有一个句子,其中有一个单词应该放在句子中另一个特定单词下面。有没有办法在不使用该\hspace选项(或将其与其他计量单位一起使用)的情况下做到这一点?

例如\hspace{cm}

\documentclass{article}

\begin{document}

\noindent
This is a sentence\\
\hspace*{1.45cm}word

\end{document}

我正在寻找一种方法,避免我猜测每对句子、单词的空间。

答案1

如果您在文档中多次需要此宏,请定义您自己的宏。此解决方案使用tabular可以嵌入在文本或数学中的任何位置的环境,以及创建常规“表格”。

您可以考虑使用不同的格式,例如更改[t]{@{}l@{}}{@{}c@{}}

\documentclass{article}

\newcommand{\stackwords}[2]{\begin{tabular}[t]{@{}l@{}}#1\\#2\end{tabular}}

\begin{document}
This is a \stackwords{sentence}{word}
\end{document}

答案2

您可以使用以下tabbing环境:

\documentclass{article}

\begin{document}

\begin{tabbing}
This is a \= sentence \\
\> word
\end{tabbing}

\end{document}

结果:

在此处输入图片描述

答案3

一种“愚蠢”的方式\hphantom{...}

\documentclass{article}

\begin{document}

\noindent
This is a sentence

\noindent\hphantom{This is a }word


\end{document}

在此处输入图片描述

编辑某种形式的自动化:

\documentclass{article}

\usepackage{xstring}
\newcommand{\displaysentence}[3]{%
\StrPosition{#1}{#2}[\somepos]%
\noindent #1

\noindent\hphantom{\StrLeft{#1}{\numexpr\somepos-1}}#3
}

\begin{document}

\noindent
This is a sentence

\noindent\hphantom{This is a }word

\displaysentence{This is a sentence}{sentence}{word}

\displaysentence{This is a very, very, very, very long sentence}{long sentence}{Here it shall be}


\end{document}

在此处输入图片描述

我当然没有检查错误,它很可能不是故障安全的。

答案4

对于单词排列的一般解决方案,语言学软件包提供的注释宏是理想的选择,因为它们还会自动换行并保持单词排列整齐。ExPex 软件包非常好用,尽管使用起来相当复杂。但 or 软件包的内置注释宏在gb4e大多数linguex情况下都能很好地发挥作用。

我可以参考的语言学中的编号示例了解这些包的概述。

这是一个仅使用cgloss4e包的简单示例(包中的文档gb4e)。该命令的工作方式是,它占用两行,每行以 结尾\\,并使用空格将每行中的每个单词对齐。分组是受尊重的,因此在您的示例中,我用括号将前三个单词分组,这样第一行实际上包含 2 个“单词”。然后,由于下一行只有一个单词,我们添加一对空括号作为第一个单词的占位符。这正确地将“单词”与“句子”对齐。

我添加了一个更长的例子来展示如何自动换行同时保持正确的单词对齐。

\documentclass{article}
\usepackage{cgloss4e} % documentation is part of gb4e
\begin{document}
\noindent
\gll {This is a} sentence.\\
{} {word}\\

\gll This package also allows very long sentences to wrap properly and can align each word.\\
     Word each align can and properly wrap to sentences long very allows also package this.\\
\end{document}

代码输出

相关内容