我有以下代码:
\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{amssymb}
\usepackage{ dsfont }
\usepackage[mathscr]{euscript}
\usepackage{booktabs}
\newcommand{\longto}{\longrightarrow}
\usepackage[a4paper,top=1cm,bottom=2cm,left=1cm,right=1cm]{geometry}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{graphicx}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%
\pagestyle{empty}
\usepackage{pgfplots}
\usepackage{eurosym}
\begin{document}
\section{graph}
\begin{tikzpicture}
\begin{axis}[
xmax=7.5, xmin=-5.5,
ymax=3.5, ymin=0,
axis x line=bottom,
axis y line=left,
axis x line=middle,
axis y line=middle,
axis equal image=true,
xlabel={\(a \in \mathbf{Set}(\{\mathbf{mis}_i(X)\}_{i=1}^6 )\)},
ylabel={\(f_a^{\text{ass}}\)},
every axis x label/.style={
at={(ticklabel* cs:1.05)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1.05)},
anchor=south,},
xtick={-4,-3,-2,-1,0,1,2,3,4,5,6},
ytick={0,1,2,3,4,5,6,7},
]
\addplot+[ycomb] plot coordinates
{(-2,1) (0,1) (1,1) (2,2) (4,1)};
\end{axis}
\end{tikzpicture}
\end{document}
输出为
我该怎么做才能得到以下输出:
或以下输出:
????? 提前致谢!
答案1
似乎您应该考虑将其作为figure
环境,尽管这并不是绝对必要的。然后,您可以以正常方式添加标题(\caption{...}
)。您可以选择使用将“图形”重命名为“图表” \renewcommand{\figurename}{Graph}
。该图形将与所有其他图形一起按适当方式编号。
但是,为了简单地将图形装箱,您可以包装其tikzpicture
内部\fbox{ ... }
。
可以通过直接添加文本来明确指定标题,如下所示:
\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{amssymb}
\usepackage{ dsfont }
\usepackage[mathscr]{euscript}
\usepackage{booktabs}
\newcommand{\longto}{\longrightarrow}
\usepackage[a4paper,top=1cm,bottom=2cm,left=1cm,right=1cm]{geometry}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{graphicx}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%
\pagestyle{empty}
\usepackage{pgfplots}
\usepackage{eurosym}
\begin{document}
\section{graph}
\renewcommand{\figurename}{Graph}
{\centering\fbox{
\begin{tikzpicture}
\begin{axis}[
xmax=7.5, xmin=-5.5,
ymax=3.5, ymin=0,
axis x line=bottom,
axis y line=left,
axis x line=middle,
axis y line=middle,
axis equal image=true,
xlabel={\(a \in \mathbf{Set}(\{\mathbf{mis}_i(X)\}_{i=1}^6 )\)},
ylabel={\(f_a^{\text{ass}}\)},
every axis x label/.style={
at={(ticklabel* cs:1.05)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1.05)},
anchor=south,},
xtick={-4,-3,-2,-1,0,1,2,3,4,5,6},
ytick={0,1,2,3,4,5,6,7},
]
\addplot+[ycomb] plot coordinates
{(-2,1) (0,1) (1,1) (2,2) (4,1)};
\end{axis}
\end{tikzpicture}}
\par\vspace{1ex} % To add appropriate space
Graph 1.0.1 --- Proof of 1.0 % Caption
\par}
\end{document}
答案2
如果您需要figure
环境,csltr 的答案很好,但如果您只想为图表添加框架和标签,则可以使用current bounding box
节点。一旦axis
环境关闭,current bounding box
节点将包含整个图表(轴、标签、图表标题等)。draw
如果您想要一个框架,您可以这样做,并且可以使用它作为参考添加更多文本节点或标签。查看下\end{axis}
一个代码中的两个命令。
\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{amssymb}
\usepackage{ dsfont }
\usepackage[mathscr]{euscript}
\usepackage{booktabs}
\newcommand{\longto}{\longrightarrow}
\usepackage[a4paper,top=1cm,bottom=2cm,left=1cm,right=1cm]{geometry}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{graphicx}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%
\pagestyle{empty}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{backgrounds}
\usepackage{eurosym}
\begin{document}
\section{graph}
\begin{tikzpicture}
\begin{axis}[
xmax=7.5, xmin=-5.5,
ymax=3.5, ymin=0,
axis x line=bottom,
axis y line=left,
axis x line=middle,
axis y line=middle,
axis equal image=true,
xlabel={\(a \in \mathbf{Set}(\{\mathbf{mis}_i(X)\}_{i=1}^6 )\)},
ylabel={\(f_a^{\text{ass}}\)},
every axis x label/.style={
at={(ticklabel* cs:1.05)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1.05)},
anchor=south,},
xtick={-4,-3,-2,-1,0,1,2,3,4,5,6},
ytick={0,1,2,3,4,5,6,7},
]
\addplot+[ycomb] plot coordinates
{(-2,1) (0,1) (1,1) (2,2) (4,1)};
\end{axis}
% Comment next line to suppress the frame
\draw[ultra thick] ([shift={(-2mm,2mm)}]current bounding box.north west) rectangle ([shift={(2mm,-2mm)}]current bounding box.south east);
\node[at =(current bounding box.south), anchor=north] {Graph 1.0.1 -- Prove 1.0};
\end{tikzpicture}
\end{document}