一行定位正确但不占用空间的文字?

一行定位正确但不占用空间的文字?

欢迎来到有关我尝试改进疯狂布局的系列问题的第 4 部分!

我正在tabu创建一个带有中心标题的表格,以及左侧和右侧两个垂直居中的小文本块。

现在我想添加一个小标题——但是主标题仍应相对于左右文本块垂直居中。这是起点:

\documentclass{article}
\usepackage{tabu} 

\begin{document}

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left
    &
    \Huge Here's a Title
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\ \tabucline \\
\end{tabu}

\end{document}

当我使用

\Huge Here's a Title \linebreak \normalsize And a subtitle!

我明白了:

显然,居中总体上是保留的,但我不希望字幕影响定位。所以我尝试了\smash

\Huge Here's a Title \smash{\linebreak \normalsize And a subtitle!}

但结果并没有更好(事实上,更糟糕):

(而且我也尝试了一些其他的安排,但都无济于事。)有什么办法可以做到这一点,还是我疯了才尝试?

答案1

根据评论,你似乎想确保副标题不占用任何空间。好吧,我通常过度杀伤使用选项tikz提供了一种放置文本而不影响定位的方法。

您通过标记希望文本居中的两个端点,\tikzmark并为每个标记命名。然后,在表格之后,您可以将文本放置在相对于这些标记点的任何位置。下面,我已将默认位置(显示为红色)设置在标题下方,但您也可以使用宏的第一个可选参数\AddSubTitle来调整定位和颜色,就像我在第二个示例中所做的那样(文本为蓝色):

在此处输入图片描述

我不确定您是否想将文本放在上面\tabucline,但这对于装饰品来说可能有意义。无论如何,您可以灵活地将其放置在您想要的位置。

也许像下面的第一个例子这样的内容可能会有用,我在文本周围添加了白色填充,以便字幕不被遮挡:

在此处输入图片描述

笔记:

代码:

\documentclass{article}
\usepackage{tabu} 
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand*{\AddSubTitle}[4][]{%
    % #1 = draw options
    % #2 = left point
    % #3 = right point
    % #4 = text
    \begin{tikzpicture}[overlay,remember picture]
        \coordinate (MidPoint) at ($(#2.south)!0.5!(#3.south)$);
        \node [red, #1] at (MidPoint)  {#4};
    \end{tikzpicture}%
}%

\newcommand{\MyTabu}{%  Make it easier to repeat for testing purposes
\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left
    &
    \Huge \tikzmark{left}Here's a Title\tikzmark{right}
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\ \tabucline \\
\end{tabu}
}%
\begin{document}

\MyTabu
\AddSubTitle{left}{right}{And a subtitle!}

\vspace*{1.0cm}
\MyTabu
\AddSubTitle[blue, yshift=0.2cm]{left}{right}{And a subtitle!}

\vspace*{1.0cm}
\MyTabu
\AddSubTitle[red, yshift=0.5cm, rotate=45]{left}{right}{And a subtitle!}

\end{document}

答案2

您可以本地禁用行间跳过机制:

\documentclass{article}
\usepackage{tabu}

\begin{document}

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline
    \scriptsize This is something \linebreak on the left
    &
    \offinterlineskip
    \Huge\strut Here's a Title\par
    \vspace{-2pt}
    \normalsize\strut And a subtitle
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\\tabucline\\
\end{tabu}

\end{document}

\vspace{-2pt}似乎是必要的,特别是因为巨大的标题没有降部。通过插入支柱,您可以确保字符不会碰到线条。

在此处输入图片描述

或者,将副标题放在另一行:

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline
    \scriptsize This is something \linebreak on the left
    &
    \Huge\strut Here's a Title
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\
    & And a subtitle & \\
\tabucline\\
\end{tabu}

在此处输入图片描述

答案3

将副标题放在横跨三列的居中多列中(我\strut在大标题后面放置了以获得更好的间距):

\documentclass{article}
\usepackage{tabu} 

\begin{document}

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left
    &
    \Huge Here's a Title\strut
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\\tabucline\\
\multicolumn{3}{|c|}{Her is the subtitle}\\ \tabucline \\
\end{tabu}

\end{document}

在此处输入图片描述

或者只是放在单独的行中(\strut在字幕之后进行实验,看看是否发现间距更好):

\documentclass{article}
\usepackage{tabu} 

\begin{document}

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left
    &
    \Huge Here's a Title\strut
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\
& Her is the subtitle \strut &\\ \tabucline \\
\end{tabu}

\end{document}

在此处输入图片描述

第三个选择是使用包文本位置。 放置 :

\documentclass{article}
\usepackage{textpos} 
\usepackage{tabu}

\setlength{\TPHorizModule}{\textwidth}
\setlength{\TPVertModule}{\textheight}


\begin{document}

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left
    &
    \Huge Here's a Title\strut
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
 \\ \tabucline \\
\end{tabu}

\begin{textblock}{0.8}[0.5,0.5](0.5,-0.01)
\noindent\centering Subtitle
\end{textblock}

\end{document}

在此处输入图片描述

答案4

你能对太空感到快乐吗phantom

\documentclass{article}
\usepackage{tabu}

\begin{document}

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left
    &
     \phantom{And a subtitle!} \Huge Here's a Title \linebreak \normalsize And a subtitle!
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \\ \tabucline \\
\end{tabu}

\noindent OR

\noindent
\begin{tabu}{|X[m,c]|X[-2,m,c]|X[m,c]|} \tabucline \\
    \scriptsize This is something \linebreak on the left \linebreak  \phantom{And a subtitle!}
    &
     \Huge Here's a Title \linebreak \normalsize And a subtitle!
    &
    \scriptsize And here's some stuff \linebreak on the \linebreak right side
    \linebreak \phantom{And a subtitle!}
    \\ \tabucline \\
\end{tabu}

\end{document}

在此处输入图片描述

相关内容