以下部分 LaTeX 代码:
\node [below=of Mesozoic, yshift=-2cm] (Jurassic) {Jurassic Period \\ 199 - 145 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL)
\end{tabular}}, \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
如下图所示:
其中“Bituminous (US/IL) '”后面有一个单引号 (')。
我想要的是在文本“Bituminous (US/IL)”后面紧接着一个逗号,以便逗号 (,) 将“Bituminous (US/IL)”与“Lignite (CN)”分开。
我在生成单引号的代码中做错了什么,我怎样才能用逗号 (,) 替换它?
如果需要的话,我可以提供完整的 LaTeX 代码。
谢谢。
更新:抱歉,我被要求提供完整的 LaTeX 代码:
注意:上述代码片段可以在“%中生代”下找到。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[landscape, margin=1cm]{geometry}
\usepackage{xcolor} % Add color package
\usetikzlibrary{trees, positioning, matrix}
\begin{document}
% Define colors
\definecolor{LigniteColor}{rgb}{0,0.5,0} % Green
\definecolor{BituminousColor}{rgb}{0,0,1} % Blue
\definecolor{AnthraciteColor}{rgb}{1,0,0} % Red
\begin{tikzpicture}[scale=0.7, every node/.style={draw=black, align=center, shape=rectangle, rounded corners}, sloped]
\node (Coal) at (0,0) {Coal Deposits};
% Cenozoic Era
\node [below left=of Coal, yshift=-1cm, xshift=-3cm] (Cenozoic) {Cenozoic Era \\ 66 Mya to Present};
\node [below left=of Cenozoic, yshift=0cm, text width=3cm] (Quaternary) {Quaternary Period \\ < 2.6 Mya \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (DE, PL, TR, US/ND, US/TX)
\end{tabular}}, \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL, CN, IN, AU, RU)
\end{tabular}}
};
\node [below=of Cenozoic, yshift=-1cm] (Tertiary) {Tertiary Period \\ 66 - 2.6 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL, CN, IN, AU, RU)
\end{tabular}}, \\ \textcolor{AnthraciteColor}{%
\begin{tabular}{@{}c@{}}
Anthracite \\ (US/PA)
\end{tabular}}
};
% Mesozoic Era
\node [below=of Coal, yshift=-2cm] (Mesozoic) {Mesozoic Era \\ 251 - 66 Mya};
\node [below left=of Mesozoic, yshift=-1cm, xshift=0.5cm] (Cretaceous) {Cretaceous Period \\ 145 - 66 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL)
\end{tabular}}, \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
\node [below=of Mesozoic, yshift=-2cm] (Jurassic) {Jurassic Period \\ 199 - 145 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL)
\end{tabular}}, \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
\node [below right=of Mesozoic, yshift=-3cm] (Triassic) {Triassic Period \\ 251 - 199 Mya \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
% Paleozoic Era
\node [below right=of Coal, yshift=-7cm, xshift=3cm] (Paleozoic) {Paleozoic Era \\ 541 - 251 Mya};
\node [below left=of Paleozoic, yshift=-1cm] (Permian) {Permian Period \\ 299 - 251 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL, AU, RU)
\end{tabular}}, \\ \textcolor{AnthraciteColor}{%
\begin{tabular}{@{}c@{}}
Anthracite \\ (RU)
\end{tabular}}
};
\node [below=of Paleozoic, yshift=-2cm] (Carboniferous) {Carboniferous Period \\ 359 - 299 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL, AU, RU)
\end{tabular}}, \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (US/ND)
\end{tabular}}
};
\node [below right=of Paleozoic, yshift=-3cm] (Devonian) {Devonian Period \\ 419 - 359 Mya \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (US/ND)
\end{tabular}}
};
\draw (Coal) -- (Cenozoic);
\draw (Cenozoic) -- (Quaternary);
\draw (Cenozoic) -- (Tertiary);
\draw (Coal) -- (Mesozoic);
\draw (Mesozoic) -- (Cretaceous);
\draw (Mesozoic) -- (Jurassic);
\draw (Mesozoic) -- (Triassic);
\draw (Coal) -- (Paleozoic);
\draw (Paleozoic) -- (Permian);
\draw (Paleozoic) -- (Carboniferous);
\draw (Paleozoic) -- (Devonian);
% Full Legend position
\node [below=of Tertiary, yshift=-1cm, xshift=0cm, text width=10cm, align=left] (Legend) {
\begin{center}
\textbf{\Large Legend:}
\end{center}
$\bullet$ \textcolor{LigniteColor}{\textbf{Lignite}}: Also known as brown coal, forms over tens of thousands to a few million years. Lowest rank of coal, lower heat content, higher moisture. Found in Germany (DE), Poland (PL), Turkey (TR), United States (North Dakota, Texas) (US/ND, US/TX), China (CN).\\[0.5em]
$\bullet$ \textcolor{BituminousColor}{\textbf{Bituminous}}: Higher-grade coal, forms over millions of years. Undergoes increased pressure and temperature, higher carbon content than lignite. Found in United States (Appalachian region, Illinois Basin) (US/IL), China (CN), India (IN), Australia (AU), Russia (RU).\\[0.5em]
$\bullet$ \textcolor{AnthraciteColor}{\textbf{Anthracite}}: Highest rank of coal, forms over long timeframes. High carbon content, low impurities, highest energy content. Found in United States (Pennsylvania) (US/PA), Russia (RU), China (CN).
};
\end{tikzpicture}
\end{document}
更新2:使用 David Carlisle 的 [b] 将单引号 (') 替换为逗号,但逗号前面有时会有空格,例如:
\node [below=of Mesozoic, yshift=-2cm] (Jurassic) {Jurassic Period \\ 199 - 145 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL)
\end{tabular}}, \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
更新 3:根据 David Carlisle 和 Jasper Habicht 的评论,我将单引号 (') 替换为逗号,并删除了逗号前的额外空格。Jasper 帮助我修正了语法,将日期范围改为“使用短划线而不是连字符”。谢谢你们。
\node [below=of Mesozoic, yshift=-2cm] (Jurassic) {Jurassic Period \\ 199--145 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL),
\end{tabular}} \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
对于将来可能需要它的人,完整修订的代码如下(注意:第四纪节点仍然需要一些工作):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[landscape, margin=1cm]{geometry}
\usepackage{xcolor} % Add color package
\usetikzlibrary{trees, positioning, matrix}
\begin{document}
% Define colors
\definecolor{LigniteColor}{rgb}{0,0.5,0} % Green
\definecolor{BituminousColor}{rgb}{0,0,1} % Blue
\definecolor{AnthraciteColor}{rgb}{1,0,0} % Red
\begin{tikzpicture}[scale=0.7, every node/.style={draw=black, align=center, shape=rectangle, rounded corners}, sloped]
\node (Coal) at (0,0) {Coal Deposits};
% Cenozoic Era
\node [below left=of Coal, yshift=-1cm, xshift=-3cm] (Cenozoic) {Cenozoic Era \\ 66 Mya to Present};
\node [below left=of Cenozoic, yshift=0cm, text width=3cm] (Quaternary) {Quaternary Period \\ < 2.6 Mya \\ \textcolor{LigniteColor}{%
\begin{tabular}[b]{@{}c@{}}
Lignite \\ (DE, PL, TR, US/ND, US/TX),
\end{tabular}} \\ \textcolor{BituminousColor}{%
\begin{tabular}{@{}c@{}}
Bituminous \\ (US/IL, CN, IN, AU, RU)
\end{tabular}}
};
\node [below=of Cenozoic, yshift=-1cm] (Tertiary) {Tertiary Period \\ 66--2.6 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL, CN, IN, AU, RU),
\end{tabular}} \\ \textcolor{AnthraciteColor}{%
\begin{tabular}{@{}c@{}}
Anthracite \\ (US/PA)
\end{tabular}}
};
% Mesozoic Era
\node [below=of Coal, yshift=-2cm] (Mesozoic) {Mesozoic Era \\ 251--66 Mya};
\node [below left=of Mesozoic, yshift=-1cm, xshift=0.5cm] (Cretaceous) {Cretaceous Period \\ 145--66 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL),
\end{tabular}} \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
\node [below=of Mesozoic, yshift=-2cm] (Jurassic) {Jurassic Period \\ 199--145 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL),
\end{tabular}} \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
\node [below right=of Mesozoic, yshift=-3cm] (Triassic) {Triassic Period \\ 251--199 Mya \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (CN)
\end{tabular}}
};
% Paleozoic Era
\node [below right=of Coal, yshift=-7cm, xshift=3cm] (Paleozoic) {Paleozoic Era \\ 541--251 Mya};
\node [below left=of Paleozoic, yshift=-1cm] (Permian) {Permian Period \\ 299--251 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL),
\end{tabular}} \\ \textcolor{AnthraciteColor}{%
\begin{tabular}{@{}c@{}}
Anthracite \\ (RU)
\end{tabular}}
};
\node [below=of Paleozoic, yshift=-2cm] (Carboniferous) {Carboniferous Period \\ 359--299 Mya \\ \textcolor{BituminousColor}{%
\begin{tabular}[b]{@{}c@{}}
Bituminous \\ (US/IL, AU, RU),
\end{tabular}} \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (US/ND)
\end{tabular}}
};
\node [below right=of Paleozoic, yshift=-3cm] (Devonian) {Devonian Period \\ 419--359 Mya \\ \textcolor{LigniteColor}{%
\begin{tabular}{@{}c@{}}
Lignite \\ (US/ND)
\end{tabular}}
};
\draw (Coal) -- (Cenozoic);
\draw (Cenozoic) -- (Quaternary);
\draw (Cenozoic) -- (Tertiary);
\draw (Coal) -- (Mesozoic);
\draw (Mesozoic) -- (Cretaceous);
\draw (Mesozoic) -- (Jurassic);
\draw (Mesozoic) -- (Triassic);
\draw (Coal) -- (Paleozoic);
\draw (Paleozoic) -- (Permian);
\draw (Paleozoic) -- (Carboniferous);
\draw (Paleozoic) -- (Devonian);
% Full Legend position
\node [below=of Tertiary, yshift=-1cm, xshift=0cm, text width=10cm, align=left] (Legend) {
\begin{center}
\textbf{\Large Legend:}
\end{center}
$\bullet$ \textcolor{LigniteColor}{\textbf{Lignite}}: Also known as brown coal, forms over tens of thousands to a few million years. Lowest rank of coal, lower heat content, higher moisture. Found in Germany (DE), Poland (PL), Turkey (TR), United States (North Dakota, Texas) (US/ND, US/TX), China (CN).\\[0.5em]
$\bullet$ \textcolor{BituminousColor}{\textbf{Bituminous}}: Higher-grade coal, forms over millions of years. Undergoes increased pressure and temperature, higher carbon content than lignite. Found in United States (Appalachian region, Illinois Basin) (US/IL), China (CN), India (IN), Australia (AU), Russia (RU).\\[0.5em]
$\bullet$ \textcolor{AnthraciteColor}{\textbf{Anthracite}}: Highest rank of coal, forms over long timeframes. High carbon content, low impurities, highest energy content. Found in United States (Pennsylvania) (US/PA), Russia (RU), China (CN).
};
\end{tikzpicture}
\end{document}
享受!
答案1
如果您放置tabular
内联,默认情况下它将垂直居中对齐到当前行。 在您的例子中,这会导致逗号“向上”移动(实际上是表格移动)。 可以通过[b]
向 中添加选项来解决tabular
此问题,这将使最后一行的基线与周围文本对齐。
此外,atabular
总是将内容排版在宽度相同的框中,这是设计使然。如果您将文本放在表格后面,而最后一个单元格中的文本恰好比整个表格短,那么自然就会有一些空间。
请考虑以下示例,其中我添加了规则来显示表格单元格的界限:
\documentclass[border=10pt]{standalone}
\begin{document}
x\begin{tabular}{|@{}c@{}|}
\hline
foo bar \\
\hline
baz \\
\hline
\end{tabular}x
\end{document}
因此,最简单的解决方案就是根本不使用tabular
s。你只需要小心地为每一行分别选择颜色:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
% Define colors
\definecolor{LigniteColor}{rgb}{0,0.5,0} % Green
\definecolor{BituminousColor}{rgb}{0,0,1} % Blue
\definecolor{AnthraciteColor}{rgb}{1,0,0} % Red
\begin{document}
\begin{tikzpicture}[
scale=0.7,
every node/.style={
align=center,
draw,
rounded corners
}
]
\node (Jurassic) {
Jurassic Period \\
199--145 Mya \\
\textcolor{BituminousColor}{Bituminous} \\
\textcolor{BituminousColor}{(US/IL)}, \\
\textcolor{LigniteColor}{Lignite} \\
\textcolor{LigniteColor}{(CN)}
};
\end{tikzpicture}
\end{document}