我有一张由两栏组成的海报。在其中一栏中,我将两个图形并排放置。为了在每个图形周围都获得一个漂亮的 tikz 框架,我必须将它们分别放入迷你页面中(我无法在没有迷你页面的情况下仅让图形周围的 tikz 框架工作……)
我现在的问题是,我想让两个元素 [tikz-framed-figure] 垂直对齐在顶部。我尝试将其与 tabular{x} 对齐,但到目前为止还没有成功。
\documentclass[englisch,a0]{KITposter}
\usepackage[latin1]{inputenc}
\usepackage[english,ngerman]{babel}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tabularx,booktabs}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tabularx}{\textwidth}[t]{cc}
\begin{tikzpicture}
\node[framed,double,ultra thick,draw=red,rounded corners=25pt] {
\begin{minipage}[H]{.45\columnwidth}
\begin{figure}
\centering
\includegraphics[width=0.95\textwidth]{./setup_1.pdf}
\label{fig:setup_1}
\end{figure}
\end{minipage}
};
\end{tikzpicture}
&
\begin{tikzpicture}
\node[framed,double,ultra thick,draw=red,rounded corners=25pt] {
\begin{minipage}[H]{.45\columnwidth}
\begin{figure}
\centering
\includegraphics[width=0.95\textwidth]{./network_1.pdf}
\label{fig:network_1}
\end{figure}
\end{minipage}
};
\end{tikzpicture}
\end{tabularx}
\end{document}
编辑
Torbjørn 建议的解决方案(具有更简化的结构且没有死重)对我来说非常有效,可以对齐 tikz 框架内的图形:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{tikzpicture}[myframe/.style={double,ultra thick,draw=red,rounded corners=25pt,inner sep=10pt}]
\node [myframe] (imga) {\includegraphics[width=0.42\textwidth]{example-image}};
\node [right=of imga.north east,anchor=north west,myframe] {\includegraphics[width=0.42\textwidth]{example-image-10x16}};
\end{tikzpicture}
谢谢您的帮助!
答案1
(我对 LaRiFaRi 的回答的评论中的建议有点不完整,所以这里有一个更完整的答案。)
您可以使用单个 来实现此目的tikzpicture
,将每个图像放在单独的节点中。不要使用backgrounds
库并修改背景矩形的样式,而是定义新样式并将其应用于每个节点。添加一个 以inner sep=10pt
防止框架覆盖图像的角落。
定位由positioning
TikZ 库处理。我将第二个节点设置为right=of imga.north east
,然后设置anchor=north west
。这意味着两个图像的顶部对齐。
您得到重叠的原因是您没有使用我的代码。您写的right of=
是 而不是right=of
。请参阅PGF/TikZ 中“right of=”和“right=of”之间的区别解释为什么会发生这种情况
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[myframe/.style={double,ultra thick,draw=red,rounded corners=25pt,inner sep=10pt}]
\node [myframe] (imga) {\includegraphics[width=0.42\textwidth]{example-image}};
\node [right=of imga.north east,anchor=north west,myframe] {\includegraphics[width=0.42\textwidth]{example-image-10x16}};
\end{tikzpicture}
\end{document}
答案2
和tcolorbox
\documentclass{article}
\usepackage[many]{tcolorbox}
\begin{document}
\begin{tcbraster}[raster columns=2,
enhanced,
raster force size=false,
size=fbox,
raster column skip=4mm,
raster right skip= 0pt,
raster left skip=0pt,
raster valign=top,
boxrule=2pt,arc=2mm,
colframe=red,colback=blue!50!black,
drop fuzzy shadow]
\tcbincludegraphics[hbox,graphics options={width=0.42\linewidth}]{example-image-a}
\tcbincludegraphics[hbox,graphics options={width=0.42\linewidth}]{example-image-10x16}
\end{tcbraster}
\end{document}
答案3
像这样吗?
% arara: pdflatex
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{tabularx}{\textwidth}[t]{YY}
\begin{tikzpicture}[framed,background rectangle/.style={double,ultra thick,draw=red,rounded corners=25pt}] % change corner size to smaller values in order to prevent touching.
\node{\includegraphics[width=0.42\textwidth]{./setup_1.pdf}
%\label{fig:setup_1} % you do not need a label if there is no caption.
};
\end{tikzpicture}
&
\begin{tikzpicture}[framed,background rectangle/.style={double,ultra thick,draw=red,rounded corners=25pt}]
\node{\includegraphics[width=0.42\textwidth]{./network_1.pdf}
%\label{fig:network_1} % you do not need a label if there is no caption.
};
\end{tikzpicture}
\end{tabularx}
\end{document}