问题 1我可以定义 x 和 y 的参考坐标,然后使用这些坐标来调整 Tikz 图片内的图形吗?
举例来说,如果我想将此图片中的所有矩形向左重新调整 0.25,我必须手动更改每个框或每个 \foreach 指令的坐标。请提供更好的解决方案。我可以在开始时定义坐标,例如 x = 0 和 y = 0,然后如果我必须重新调整矩形,我只需将 x 更改为 -0.25 并将 y 更改为 -0.25。
问题2我怎样才能将 tikzpicture 置于会议论文的一栏中央?
平均能量损失
\ifCLASSINFOpdf
\else
\fi
\usepackage[usenames,dvipsnames]{color}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.multipart}
\usepackage[caption=false]{subfig}
\usepackage{tabularx,tikz}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\title{Bare Demo of IEEEtran.cls for Conferences}
\maketitle
\IEEEpeerreviewmaketitle
\section{Introduction}
I wish you the best of success.
\begin{tikzpicture}
%Can I give a reference coordinate such as x = 0 and y = 0 and then draw figures
%based on that reference points through out the picture?
\draw [rounded corners](0,0) rectangle +(9,6);
\draw [rounded corners](0.15,0.5) node[above right, font =\small,align=center,text width = 2cm]{YYYY} rectangle +(2.25,5);
\foreach \x in {2.5}
\foreach \y in {0.5,3,4.5}
{
\draw [rounded corners] (\x,\y) rectangle +(6.35,1);
}
\foreach \x in {2.75,4.25,5.75,7.25}
\foreach \y in {0.9,3.4,4.9}
{
\draw [rounded corners] (\x, \y) node[above right, font=\scriptsize,text width = 1.8cm] {XXX} rectangle +(1.2,0.5);
}
\end{tikzpicture}
\end{document}
谢谢!
答案1
您可以使用calc
:
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, calc}
\begin{document}
\begin{tikzpicture}
\coordinate (ref) at (0,0);
\draw [rounded corners](ref) rectangle +(9,6);
\draw [rounded corners]($(ref) + (0.15,0.5)$) node[above right, font =\small,align=center,text width = 2cm]{YYYY} rectangle +(2.25,5);
\foreach \x in {2.5}
\foreach \y in {0.5,3,4.5}
{
\draw [rounded corners] ($(ref) + (\x,\y)$) rectangle +(6.35,1);
}
\foreach \x in {2.75,4.25,5.75,7.25}
\foreach \y in {0.9,3.4,4.9}
{
\draw [rounded corners] ($(ref) + (\x, \y)$) node[above right, font=\scriptsize,text width = 1.8cm] {XXX} rectangle +(1.2,0.5);
}
\coordinate (ref) at (-0.25,-0.25);
\tikzset{color=red}
\draw [rounded corners](ref) rectangle +(9,6);
\draw [rounded corners]($(ref) + (0.15,0.5)$) node[above right, font =\small,align=center,text width = 2cm]{YYYY} rectangle +(2.25,5);
\foreach \x in {2.5}
\foreach \y in {0.5,3,4.5}
{
\draw [rounded corners] ($(ref) + (\x,\y)$) rectangle +(6.35,1);
}
\foreach \x in {2.75,4.25,5.75,7.25}
\foreach \y in {0.9,3.4,4.9}
{
\draw [rounded corners] ($(ref) + (\x, \y)$) node[above right, font=\scriptsize,text width = 1.8cm] {XXX} rectangle +(1.2,0.5);
}
\end{tikzpicture}
\end{document}