使用 subfig 包时 Tikzpicture 不居中

使用 subfig 包时 Tikzpicture 不居中

我正在写一个文档,并试图将 tikz 图片作为子图居中放置。虽然它似乎具有合适的大小(我使用 fbox 进行了检查),但图像并未居中在列的中间。这是怎么回事?我读过一些关于其他人的 tikzpictures 上不可见节点占用空间的文章,但我认为这不是我的情况。

下面是我使用的 TEX 文件。我使用 'showframe' 包检查图片是否溢出边缘,并使用 'fbox' 检查图片是否太大。请注意,我使用的是 'subfig' 包,而不是 'subcaption',因为我已经在 IEEEtrans 模板中发现它已定义,我不确定是否可以更改它。

我将非常感激任何帮助!:)

该文件的 MWE:

\documentclass[conference,a4paper]{IEEEtran}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\interdisplaylinepenalty=2500
\usepackage{algorithmic}
\usepackage{textcomp}
\usepackage{xcolor}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
   T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

%- Supporting packages
\usepackage{lipsum}
\usepackage{showframe}

%- Figures and subfigures packages
\usepackage[caption=false,font=footnotesize]{subfig}
\usepackage[pdftex]{graphicx}

%- Last package to write, as it loads a bunch of them, an it could give clash problems
\usepackage{pgfplotstable} % Loads a bunch of packages
\pgfplotsset{compat=newest}

%- Loading of libraries from  pre-loaed packages
\usetikzlibrary{math,% For computations. Variables must be declared in a tikzmath environment but can be used outside
                       decorations.markings,       % For arrow tips
                      decorations.pathreplacing, % For brackets on image
                      calligraphy,}                        % For brackets on image
\tikzstyle{help lines}=[thin,gray!40]


\begin{document}

\title{A title
}

\author{Jes
       \\
   \IEEEauthorblockA{LaTeX is not easy}
   }
\maketitle

\begin{abstract}
\lipsum[1]
\end{abstract}

\begin{IEEEkeywords}
   Ipsum lipsum diggity tippity.
\end{IEEEkeywords}


%- Sections
\section{Introduction}
\lipsum[1-3]

\begin{figure}[h]
   \centering
   \subfloat[]{\fbox{
           \input{Tikzpicture.tex}%
   }}
   \vfil
   \subfloat[]{
       \def\svgwidth{3.15in}
       \input{Tikzpicture.tex}%
   }
   
   \caption{This is a caption}
   
   \label{fig:IndoorLocSketch}
\end{figure}

\lipsum[1]

\end{document}

这里是 Tikzpicture 使用的代码:

%- Define colors to be used
\definecolor{Color Lens}{rgb}{0, 1, 0.5}            % Color for lens
\definecolor{Color FSS}{rgb}{1.0, 0.49, 0.0}        % Color FSS
\definecolor{Color IncWave}{rgb}{0,0,1}             % Color incoming wave
\definecolor{Color SurfRefl}{rgb}{0.0, 0.72, 0.92}  % Color surface refraction
\definecolor{Color ResFreq}{rgb}{1.0, 0.49, 0.0}    % Color f0
\definecolor{Color FocalPoint}{rgb}{0.03, 0.47, 0.19}

%\begin{document}
    \tikzmath{
        \LensCenterX = 6;
        \LensCenterY =  0;
        \LensRadius  = 1.75; % In cm
        \FSSThick    = 1;    % In mm
        \ArrowPos    = (2/3)*\LensRadius;
        \ArrowThick  = 0.3; % In mm
    } 

    \begin{tikzpicture}[scale=0.43,every node/.style={scale=0.9}]
        %- Help grid
        %\draw [help lines, step=1] (-12,-5) grid (11,5);
        
        %- Lens
        \draw [color = Color Lens, fill=Color Lens]
            (\LensCenterX,\LensCenterY) circle (\LensRadius cm);
        
        %- Inner lens drawing
        \draw[color = Color FSS,line width=\ArrowThick mm,-stealth]
        (\LensCenterX-1,\ArrowPos) --  (\LensCenterX+1,0.33) node [midway, below]{$f_0$};
        \draw[color = Color FSS,line width=\ArrowThick mm,-stealth]
        (\LensCenterX+1,-0.33) --  (\LensCenterX-1,-\ArrowPos);
        
        %- Lens focal point
        \draw [color = Color FocalPoint, fill = Color FocalPoint]
        (\LensCenterX+1.3,0) circle (0.33 cm);
        
        %- Metallic backside
        \draw [color=Color FSS,line width=\FSSThick mm] 
            (\LensCenterX,\LensRadius) arc (-90:90:-\LensRadius cm);       % Backside metallization
        
        %- FSS
        \draw [color=black,line width=\FSSThick mm] 
            (\LensCenterX,-\LensRadius) arc (90:270:-\LensRadius cm);      % FSS
            
        %- Annotate FSS
        \node [anchor=west,color=Color FSS,inner sep=0,outer sep=0] (FSS) at (\LensCenterX-\LensRadius-0.1,2.3) {FSS (Passband)};
        
        %- Annotate lens
        \draw[-stealth,line width=\ArrowThick mm] (\LensCenterX-2,-2.5) 
            node [anchor = north] {Lens} -- (\LensCenterX,-\LensRadius+0.3);    
            
        %- Annotate metal
        \draw[-stealth,line width=\ArrowThick mm] (\LensCenterX-0.25,-2.5)
            node [anchor = north] {Metal} -- (\LensCenterX+0.5,-1.9);
        %- Annotate Retroreflector
        \draw[line width=\ArrowThick mm, decoration={calligraphic brace,mirror,raise=-1pt,amplitude=10pt},decorate]
        (3,-3.25) -- node[below=6pt] {Retroreflector} (6.7,-3.25);
            
        %- Annotate focal point
        \draw[-stealth,line width=\ArrowThick mm] (8,-1.5) 
            node [anchor = north,align = left,inner sep=0,outer sep=0] {Focal \\ point} -- (\LensCenterX+1.4,-0.2);     
                    
        %- Arrows
        \draw[stealth-,line width=\ArrowThick mm, color = Color IncWave]
            (\LensCenterX-\LensRadius-0.5,\ArrowPos) 
            --  (-\LensCenterX+2,\ArrowPos)
            node [anchor=south west] {\color{black} Incoming wave};
            
        \draw[-stealth,line width=\ArrowThick mm, color = Color SurfRefl] 
            (\LensCenterX-\LensRadius-0.5,0) 
            node [anchor=south east] {\color{black} Surface reflection (no $f_0$) }
            -- (-\LensCenterX+2,0);
            
        \draw[-stealth,line width=\ArrowThick mm, color = Color ResFreq] 
            (\LensCenterX-\LensRadius-0.5,-\ArrowPos) 
            node [anchor=south east] {\color{black} $f_0$ (Delayed)} 
            --  (-\LensCenterX+2,-\ArrowPos);
            
        %- Reader text
        \node[anchor = center] (Reader) at (-7.25,-1) {Reader};
        %- Reader box
        \draw [line width=\ArrowThick mm] (-8.5,-0.25) rectangle +(2.5,-1.5);
        %- Reader antenna
        \draw [line width=\ArrowThick mm] (-6,-1) -- ++(0.75,0) -- ++(0,1.6) --++(0,-0.8) --++ (0.35,0.8) --++ (-0.35,-0.8) --++ (-0.35,0.8);
        
    \end{tikzpicture}

答案1

位移的原因很简单:很多不必要的空格。它从主文件开始。在所有标记的位置,%为了避免出现虚假空格,都是必要的。

   \subfloat[]{\fbox{% <<< HERE
           \input{Tikzpicture.tex}% <<< HERE
   }}
   \vfil
   \subfloat[]{% <<< HERE
       \def\svgwidth{3.15in}% <<< HERE
       \input{Tikzpicture.tex}% <<< HERE
   }

情况变得非常糟糕Tikzpicture.tex

\definecolor{Color Lens}{rgb}{0, 1, 0.5}% <<< HERE           % Color for lens
\definecolor{Color FSS}{rgb}{1.0, 0.49, 0.0}% <<< HERE       % Color FSS
\definecolor{Color IncWave}{rgb}{0,0,1}% <<< HERE            % Color incoming wave
\definecolor{Color SurfRefl}{rgb}{0.0, 0.72, 0.92}% <<< HERE % Color surface refraction
\definecolor{Color ResFreq}{rgb}{1.0, 0.49, 0.0}% <<< HERE   % Color f0
\definecolor{Color FocalPoint}{rgb}{0.03, 0.47, 0.19}% <<< HERE
% <<< HERE
%\begin{document}
    \tikzmath{
        \LensCenterX = 6;
        \LensCenterY =  0;
        \LensRadius  = 1.75; % In cm
        \FSSThick    = 1;    % In mm
        \ArrowPos    = (2/3)*\LensRadius;
        \ArrowThick  = 0.3; % In mm
    }% <<< HERE
% <<< HERE
    \begin{tikzpicture}[scale=0.43,every node/.style={scale=0.9}]

在此处输入图片描述

主文本

\documentclass[conference,a4paper]{IEEEtran}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\interdisplaylinepenalty=2500
\usepackage{algorithmic}
\usepackage{textcomp}
\usepackage{xcolor}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
   T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

%- Supporting packages
\usepackage{lipsum}
\usepackage{showframe}

%- Figures and subfigures packages
\usepackage[caption=false,font=footnotesize]{subfig}
\usepackage[pdftex]{graphicx}

%- Last package to write, as it loads a bunch of them, an it could give clash problems
\usepackage{pgfplotstable} % Loads a bunch of packages
\pgfplotsset{compat=newest}

%- Loading of libraries from  pre-loaed packages
\usetikzlibrary{math,% For computations. Variables must be declared in a tikzmath environment but can be used outside
                       decorations.markings,       % For arrow tips
                      decorations.pathreplacing, % For brackets on image
                      calligraphy,}                        % For brackets on image
\tikzstyle{help lines}=[thin,gray!40]


\begin{document}

\title{A title
}

\author{Jes
       \\
   \IEEEauthorblockA{LaTeX is not easy}
   }
\maketitle

\begin{abstract}
\lipsum[1]
\end{abstract}

\begin{IEEEkeywords}
   Ipsum lipsum diggity tippity.
\end{IEEEkeywords}


%- Sections
\section{Introduction}
\lipsum[1-3]

\begin{figure}[h]
   \centering
   \subfloat[]{\fbox{%
           \input{Tikzpicture.tex}%
   }}
   \vfil
   \subfloat[]{%
       \def\svgwidth{3.15in}%
       \input{Tikzpicture.tex}%
   }
   
   \caption{This is a caption}
   
   \label{fig:IndoorLocSketch}
\end{figure}

\lipsum[1]

\end{document}

Tikz图片.tex

%- Define colors to be used
\definecolor{Color Lens}{rgb}{0, 1, 0.5}%            % Color for lens
\definecolor{Color FSS}{rgb}{1.0, 0.49, 0.0}%        % Color FSS
\definecolor{Color IncWave}{rgb}{0,0,1}%             % Color incoming wave
\definecolor{Color SurfRefl}{rgb}{0.0, 0.72, 0.92}%  % Color surface refraction
\definecolor{Color ResFreq}{rgb}{1.0, 0.49, 0.0}%    % Color f0
\definecolor{Color FocalPoint}{rgb}{0.03, 0.47, 0.19}%
%
%\begin{document}
    \tikzmath{
        \LensCenterX = 6;
        \LensCenterY =  0;
        \LensRadius  = 1.75; % In cm
        \FSSThick    = 1;    % In mm
        \ArrowPos    = (2/3)*\LensRadius;
        \ArrowThick  = 0.3; % In mm
    }% 
%
    \begin{tikzpicture}[scale=0.43,every node/.style={scale=0.9}]
        %- Help grid
        %\draw [help lines, step=1] (-12,-5) grid (11,5);
        
        %- Lens
        \draw [color = Color Lens, fill=Color Lens]
            (\LensCenterX,\LensCenterY) circle (\LensRadius cm);
        
        %- Inner lens drawing
        \draw[color = Color FSS,line width=\ArrowThick mm,-stealth]
        (\LensCenterX-1,\ArrowPos) --  (\LensCenterX+1,0.33) node [midway, below]{$f_0$};
        \draw[color = Color FSS,line width=\ArrowThick mm,-stealth]
        (\LensCenterX+1,-0.33) --  (\LensCenterX-1,-\ArrowPos);
        
        %- Lens focal point
        \draw [color = Color FocalPoint, fill = Color FocalPoint]
        (\LensCenterX+1.3,0) circle (0.33 cm);
        
        %- Metallic backside
        \draw [color=Color FSS,line width=\FSSThick mm] 
            (\LensCenterX,\LensRadius) arc (-90:90:-\LensRadius cm);       % Backside metallization
        
        %- FSS
        \draw [color=black,line width=\FSSThick mm] 
            (\LensCenterX,-\LensRadius) arc (90:270:-\LensRadius cm);      % FSS
            
        %- Annotate FSS
        \node [anchor=west,color=Color FSS,inner sep=0,outer sep=0] (FSS) at (\LensCenterX-\LensRadius-0.1,2.3) {FSS (Passband)};
        
        %- Annotate lens
        \draw[-stealth,line width=\ArrowThick mm] (\LensCenterX-2,-2.5) 
            node [anchor = north] {Lens} -- (\LensCenterX,-\LensRadius+0.3);    
            
        %- Annotate metal
        \draw[-stealth,line width=\ArrowThick mm] (\LensCenterX-0.25,-2.5)
            node [anchor = north] {Metal} -- (\LensCenterX+0.5,-1.9);
        %- Annotate Retroreflector
        \draw[line width=\ArrowThick mm, decoration={calligraphic brace,mirror,raise=-1pt,amplitude=10pt},decorate]
        (3,-3.25) -- node[below=6pt] {Retroreflector} (6.7,-3.25);
            
        %- Annotate focal point
        \draw[-stealth,line width=\ArrowThick mm] (8,-1.5) 
            node [anchor = north,align = left,inner sep=0,outer sep=0] {Focal \\ point} -- (\LensCenterX+1.4,-0.2);     
                    
        %- Arrows
        \draw[stealth-,line width=\ArrowThick mm, color = Color IncWave]
            (\LensCenterX-\LensRadius-0.5,\ArrowPos) 
            --  (-\LensCenterX+2,\ArrowPos)
            node [anchor=south west] {\color{black} Incoming wave};
            
        \draw[-stealth,line width=\ArrowThick mm, color = Color SurfRefl] 
            (\LensCenterX-\LensRadius-0.5,0) 
            node [anchor=south east] {\color{black} Surface reflection (no $f_0$) }
            -- (-\LensCenterX+2,0);
            
        \draw[-stealth,line width=\ArrowThick mm, color = Color ResFreq] 
            (\LensCenterX-\LensRadius-0.5,-\ArrowPos) 
            node [anchor=south east] {\color{black} $f_0$ (Delayed)} 
            --  (-\LensCenterX+2,-\ArrowPos);
            
        %- Reader text
        \node[anchor = center] (Reader) at (-7.25,-1) {Reader};
        %- Reader box
        \draw [line width=\ArrowThick mm] (-8.5,-0.25) rectangle +(2.5,-1.5);
        %- Reader antenna
        \draw [line width=\ArrowThick mm] (-6,-1) -- ++(0.75,0) -- ++(0,1.6) --++(0,-0.8) --++ (0.35,0.8) --++ (-0.35,-0.8) --++ (-0.35,0.8);
        
    \end{tikzpicture}%

相关内容