我在将图片置于 LaTeX 文档的中心时遇到了问题。我想将以下图片置于中心:
\documentclass[10pt]{article}
\usepackage{pgf,tikz,geometry}
\geometry{a4paper}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-4.3,0.) -- (18.24,0.);
\foreach \x in {-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.,-5.46) -- (0.,6.3);
\foreach \y in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.3,-5.46) rectangle (18.24,6.3);
\fill[color=zzttqq,fill=zzttqq,fill opacity=0.1] (5.02,4.58) -- (1.14,-1.68) -- (10.16,-1.64) -- cycle;
\draw [color=zzttqq] (5.02,4.58)-- (1.14,-1.68);
\draw [color=zzttqq] (1.14,-1.68)-- (10.16,-1.64);
\draw [color=zzttqq] (10.16,-1.64)-- (5.02,4.58);
\draw (5.02,4.58)-- (5.444270493230518,-1.6609123259723702);
\draw (1.14,-1.68)-- (7.330385094078737,1.784164341406664);
\draw (10.16,-1.64)-- (3.1879758358533326,1.6242084361963565);
\begin{scriptsize}
\draw [fill=qqqqff] (5.02,4.58) circle (1.5pt);
\draw[color=qqqqff] (5.16,4.86) node {$A$};
\draw [fill=qqqqff] (1.14,-1.68) circle (1.5pt);
\draw[color=qqqqff] (1.08,-1.92) node {$B$};
\draw [fill=qqqqff] (10.16,-1.64) circle (1.5pt);
\draw[color=qqqqff] (10.3,-1.36) node {$C$};
\draw [fill=qqqqff] (5.287774051225104,0.6411110045818896) circle (1.5pt);
\draw[color=qqqqff] (5.14,0.4) node {$I$};
\draw [fill=qqqqff] (3.1879758358533326,1.6242084361963565) circle (1.5pt);
\draw[color=qqqqff] (2.82,1.58) node {$E$};
\draw [fill=qqqqff] (5.444270493230518,-1.6609123259723702) circle (1.5pt);
\draw[color=qqqqff] (5.62,-1.82) node {$D$};
\draw [fill=qqqqff] (7.330385094078737,1.784164341406664) circle (1.5pt);
\draw[color=qqqqff] (7.64,1.74) node {$F$};
\draw[color=black] (4.96,1.6) node {$g$};
\draw[color=black] (4.44,-0.06) node {$h$};
\draw[color=black] (6.86,0.46) node {$i$};
\end{scriptsize}
\end{tikzpicture}
\end{document}
有人能帮我指出如何将这张图片(及其标题)置于中心吗?该\centering
命令不起作用。
笔记:-我所说的“居中”是指与文本居中可以通过使用\begin{center}...\end{center}
或 来实现$\text{}$
。
答案1
如果你把它弄得足够小以适合页面(我添加了scale=.5
),它就会居中,然后添加\centering
和\end{document}
\documentclass[10pt]{article}
\usepackage{pgf,tikz,geometry}
\geometry{a4paper}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\centering
X\dotfill X
\bigskip
\definecolor{zzttqq}{rgb}{0.6,0.2,0.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm,scale=.5]
\draw[->,color=black] (-4.3,0.) -- (18.24,0.);
\foreach \x in {-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.,-5.46) -- (0.,6.3);
\foreach \y in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.3,-5.46) rectangle (18.24,6.3);
\fill[color=zzttqq,fill=zzttqq,fill opacity=0.1] (5.02,4.58) -- (1.14,-1.68) -- (10.16,-1.64) -- cycle;
\draw [color=zzttqq] (5.02,4.58)-- (1.14,-1.68);
\draw [color=zzttqq] (1.14,-1.68)-- (10.16,-1.64);
\draw [color=zzttqq] (10.16,-1.64)-- (5.02,4.58);
\draw (5.02,4.58)-- (5.444270493230518,-1.6609123259723702);
\draw (1.14,-1.68)-- (7.330385094078737,1.784164341406664);
\draw (10.16,-1.64)-- (3.1879758358533326,1.6242084361963565);
\begin{scriptsize}
\draw [fill=qqqqff] (5.02,4.58) circle (1.5pt);
\draw[color=qqqqff] (5.16,4.86) node {$A$};
\draw [fill=qqqqff] (1.14,-1.68) circle (1.5pt);
\draw[color=qqqqff] (1.08,-1.92) node {$B$};
\draw [fill=qqqqff] (10.16,-1.64) circle (1.5pt);
\draw[color=qqqqff] (10.3,-1.36) node {$C$};
\draw [fill=qqqqff] (5.287774051225104,0.6411110045818896) circle (1.5pt);
\draw[color=qqqqff] (5.14,0.4) node {$I$};
\draw [fill=qqqqff] (3.1879758358533326,1.6242084361963565) circle (1.5pt);
\draw[color=qqqqff] (2.82,1.58) node {$E$};
\draw [fill=qqqqff] (5.444270493230518,-1.6609123259723702) circle (1.5pt);
\draw[color=qqqqff] (5.62,-1.82) node {$D$};
\draw [fill=qqqqff] (7.330385094078737,1.784164341406664) circle (1.5pt);
\draw[color=qqqqff] (7.64,1.74) node {$F$};
\draw[color=black] (4.96,1.6) node {$g$};
\draw[color=black] (4.44,-0.06) node {$h$};
\draw[color=black] (6.86,0.46) node {$i$};
\end{scriptsize}
\end{tikzpicture}
\end{document}