![Tikz 依赖性和 gb4e 对齐问题](https://linux22.com/image/394550/Tikz%20%E4%BE%9D%E8%B5%96%E6%80%A7%E5%92%8C%20gb4e%20%E5%AF%B9%E9%BD%90%E9%97%AE%E9%A2%98.png)
我在一个示例中使用了 tikz-dependency 和 gb4e。我希望它们居中,但我无法做到。以下是我自己实现的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{gb4e}
\exewidth{(\thexnumi)}
\noautomath
\usepackage{tikz-dependency}
\tikzset{/depgraph/.cd,/depgraph/.search also = {/tikz},
baseline=-0.6ex, inner sep=-0.1cm, edge horizontal padding=3pt, edge unit distance=1.8ex}
\title{stackoverflow}
\author{Utku Turk}
\date{April 2019}
\begin{document}
\maketitle
\begin{figure}[]
\centering
\begin{exe}
\centering
\ex
\scalebox{1.1}{
\begin{dependency}
\begin{deptext}[column sep=.3cm]
This \& is \& a \& sentence \\
\end{deptext}
\deproot{4}{\textsc{root}}
\depedge{2}{1}{\textsc{syn2}}
\depedge[edge style={ultra thick}]{4}{2}{\textsc{\textbf{syn1}}}
\depedge[edge unit distance=3ex,edge style={densely dotted}]{4}{2}{\textsc{syn3}}
\depedge{4}{3}{\textsc{syn4}}
\wordgroup{1}{1}{2}{syn5}
\end{dependency}
}
\gll This is a sentence. \\
this is a gloss \\
\glt ``Translation of what is what"
\label{ex:sentence}
\end{exe}
\caption{vvvvvvvvv. }
\label{secondexample}
\end{figure}
\end{document}
我尝试过图形居中、exe 内部居中,还尝试过在句子周围使用 \hfill 和 \hfill \null。但都没有用。谢谢你的帮助。
现在,我找到了一种方法来避免这种情况的发生。我\hspace{110pt}
在示例之前添加了。并根据句子的长度更改了值。
但我仍然欣赏有更好的方法。
答案1
我不确定您是否希望将示例和数字居中,或者仅将内容和示例数字像往常一样左对齐,但您可以使用包将整个示例居中varwidth
,这会将小页面创建为其内容的自然宽度。这是一个仅将内容居中并将数字左对齐的版本。我们通过将环境包装varwidth
在两个\hfil
命令之间来实现这一点。
\documentclass{article}
\usepackage{gb4e}
\usepackage{varwidth}
\exewidth{(\thexnumi)}
\noautomath
\usepackage{tikz-dependency}
\tikzset{/depgraph/.cd,/depgraph/.search also = {/tikz},
baseline=-0.6ex, inner sep=-0.1cm, edge horizontal padding=3pt, edge unit distance=1.8ex}
\title{stackoverflow}
\author{Utku Turk}
\date{April 2019}
\begin{document}
\maketitle
\begin{exe}
\ex\hfil
\begin{varwidth}{\linewidth}
\scalebox{1.1}{
\begin{dependency}
\begin{deptext}[column sep=.3cm]
This \& is \& a \& sentence \\
\end{deptext}
\deproot{4}{\textsc{root}}
\depedge{2}{1}{\textsc{syn2}}
\depedge[edge style={ultra thick}]{4}{2}{\textsc{\textbf{syn1}}}
\depedge[edge unit distance=3ex,edge style={densely dotted}]{4}{2}{\textsc{syn3}}
\depedge{4}{3}{\textsc{syn4}}
\wordgroup{1}{1}{2}{syn5}
\end{dependency}
}
\gll This is a sentence. \\
this is a gloss \\
\glt ``Translation of what is what"
\label{ex:sentence}
\end{varwidth}\hfil
\end{exe}
\end{document}
或者,如果您希望内容和示例编号都居中,那么您可以在环境varwidth
内使用center
。
\documentclass{article}
\usepackage{gb4e}
\usepackage{varwidth}
\exewidth{(\thexnumi)}
\noautomath
\usepackage{tikz-dependency}
\tikzset{/depgraph/.cd,/depgraph/.search also = {/tikz},
baseline=-0.6ex, inner sep=-0.1cm, edge horizontal padding=3pt, edge unit distance=1.8ex}
\title{stackoverflow}
\author{Utku Turk}
\date{April 2019}
\begin{document}
\maketitle
\begin{center}
\begin{varwidth}{\textwidth}
\begin{exe}
\ex
\scalebox{1.1}{
\begin{dependency}
\begin{deptext}[column sep=.3cm]
This \& is \& a \& sentence \\
\end{deptext}
\deproot{4}{\textsc{root}}
\depedge{2}{1}{\textsc{syn2}}
\depedge[edge style={ultra thick}]{4}{2}{\textsc{\textbf{syn1}}}
\depedge[edge unit distance=3ex,edge style={densely dotted}]{4}{2}{\textsc{syn3}}
\depedge{4}{3}{\textsc{syn4}}
\wordgroup{1}{1}{2}{syn5}
\end{dependency}
}
\gll This is a sentence. \\
this is a gloss \\
\glt ``Translation of what is what"
\label{ex:sentence}
\end{exe}
\end{varwidth}
\end{center}
\end{document}