如何在 LaTeX 中对内容进行装箱,使所有框都在同一行且高度相同?

发布于 2024-08-09 14:53:35 字数 479 浏览 9 评论 0原文

我需要用方框包围的按键文本来表示计算器按键。我试图只按一下按键(没有盒子)就可以逃脱惩罚,但我因此被扣分,因为我的评估员似乎有点学究气。

无论如何,一些研究发现了 \boxit 和 \fbox 之类的东西。

我对它们都进行了尝试,但 \boxit 产生的结果与 \fbox 几乎相同。 问题在于框的高度和基线随其包含的字形而变化。

以下面的例子表示按 5、乘、x;

\documentclass{article}
\usepackage{fullpage}
\begin{document}
\fbox{5} \fbox{$\times$} \fbox{$x$}
\end{document}

这会在内容周围生成框,但它们位于不同的基线上,并且高度也不同。

鉴于到目前为止我所看到的 LaTeX,我想说这绝对是可能的,但 CTAN、新闻组和谷歌到目前为止还没有发现任何有用的东西。

有什么提示吗?

I need to represent calculator key presses by the text for the keys to press surrounded by a box. I tried to get away with just the bare key presses (no box) but I got marked down for it because it would appear my assessor is a bit of a pedant.

Anyway, a bit of research turned up the likes of \boxit and \fbox.

I gave them both a go but \boxit produces nigh on identical results to \fbox.
The problem is that the height and baseline of the box varies with the glyphs it contains.

Take the following example that represents pressing 5, multiply, x;

\documentclass{article}
\usepackage{fullpage}
\begin{document}
\fbox{5} \fbox{$\times$} \fbox{$x$}
\end{document}

This generates boxes around the content but they're on different baselines and they're all different heights.

Given what I've seen of LaTeX thus far I'd say this is definitely possible but CTAN, news groups and google have turned up nothing useful thus far.

Any hints?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奶气 2024-08-16 14:53:35

使用 \strut 使高度相同。

\def\press#1{\fbox{\hbox to 1em{\strut\hfil#1\hfil}}}
\press{5} \press{$\times$} \press{$x$}

或设置盒子的任意高度和深度:

\def\press#1{{\setbox0=\hbox to 1em{\hfil#1\hfil}\ht0=7.5pt \dp0=2.5pt \fbox{\box0}}}
\press{5} \press{$\times$} \press{$x$}

Using \strut to make the same height.

\def\press#1{\fbox{\hbox to 1em{\strut\hfil#1\hfil}}}
\press{5} \press{$\times$} \press{$x$}

or set any height and depth of your box:

\def\press#1{{\setbox0=\hbox to 1em{\hfil#1\hfil}\ht0=7.5pt \dp0=2.5pt \fbox{\box0}}}
\press{5} \press{$\times$} \press{$x$}
小梨窩很甜 2024-08-16 14:53:35

这看起来很接近您想要做的事情。

\framebox[2em][c]{5\strut} 
\framebox[2em][c]{$\times$\strut} 
\framebox[2em][c]{$x$\strut}

您可能想要创建一个新命令来创建密钥,以避免重复自己:

\newcommand{\key}[1]{\framebox[2em][c]{#1\strut}}
\key{5}
\key{$\times$}
\key{$x$}

我确实找到了一个名为 key Strike.sty,但这对于您想要做的事情来说可能有点过分了。

This looks close to what you are trying to do.

\framebox[2em][c]{5\strut} 
\framebox[2em][c]{$\times$\strut} 
\framebox[2em][c]{$x$\strut}

You may want to create a new command to create the keys, to avoid repeating yourself:

\newcommand{\key}[1]{\framebox[2em][c]{#1\strut}}
\key{5}
\key{$\times$}
\key{$x$}

I did find a package called keystroke.sty, but it may be overkill for what you're trying to do.

掩于岁月 2024-08-16 14:53:35

我能想到的最好的答案是:

\newcommand{\vlen}[1]{\parbox[c][#1]{0cm}{}}
\fbox{\vlen{1cm}5} \fbox{\vlen{1cm}$\times$} \fbox{\vlen{1cm}$x$}

是的。

The best I can come up with:

\newcommand{\vlen}[1]{\parbox[c][#1]{0cm}{}}
\fbox{\vlen{1cm}5} \fbox{\vlen{1cm}$\times$} \fbox{\vlen{1cm}$x$}

Yegh.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文