\documentclass[UTF8,fontset=none,scheme=chinese,twoside,a5paper]{ctexbook}
\setCJKmainfont{Noto Serif CJK TC}
\setCJKsansfont{Noto Sans CJK TC}
\ctexset{chapter/format=\LARGE\bfseries\centering\sffamily,chapter/number=\arabic{chapter}}
\usepackage[margin=2cm]{geometry}
\usepackage[cam,a4,center,noinfo]{crop}
\usepackage{tikz}
\usetikzlibrary{angles,calc,intersections,quotes}
\usepackage{caption}
\captionsetup[figure]{name=圖}
\renewcommand\thefigure{\thechapter-\arabic{figure}}
\begin{document}
\chapter[]{}
\begin{center}
\begin{tikzpicture}[scale=1.2]
\draw [gray] (0,0) circle [radius=2cm];
\fill (0,0) circle [radius=1pt];
\coordinate [label=left:$A$] (A) at (195:2cm);
\coordinate [label=left:$B$] (B) at (125:2cm);
\coordinate [label=right:$C$] (C) at (55:2cm);
\coordinate [label=right:$D$] (D) at (-15:2cm);
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\pic [draw,angle radius=3mm] {angle = A--B--C};
\pic [draw,angle radius=3mm] {angle = B--C--D};
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\draw (-3.5,0) -- (3.5,0) coordinate (x axis);
\draw (0,-3.5) -- (0,3.5) coordinate (y axis);
\draw [gray] (0,0) coordinate (O) circle [radius=3cm];
\path [name path=upward line] (3,0) coordinate (B) -- (3,3);
\path [name path=sloped line] (O) -- (30:6cm);
\path [name intersections={of=upward line and sloped line, by=C}];
\draw (C) node [above right,inner sep=1pt] {$C$} -- (O) node [below left,inner sep=1pt] {$O$}; %CO
\draw (C) -- node [right,inner sep=1pt] {$\tan x$} (B) node [below right,inner sep=1pt] {$B$}; %CB, tanx
\pic [draw,angle radius=1.5mm] {right angle = x axis--B--C}; %CB垂直x axis
\coordinate (A) at (30:3cm);
\coordinate (D) at (A|-x axis);
\draw (A) node [above,xshift=2pt,yshift=1pt] {$A$} -- node [left,inner sep=1pt] {$\sin x$} (D) node [below,inner sep=1pt] {$D$}; %AD, sinx
\pic [draw,angle radius=1.5mm] {right angle = x axis--D--A}; %AD垂直x axis
\draw (A) -- (B); %AB
\path (O) -- node [above] {$1$} (A); %半徑1
\pic [draw,angle radius=5mm,angle eccentricity=1.5,"$x$"] {angle = B--O--A};
\node [right,inner sep=1pt] at (25:3cm) {$x$};
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\end{document}
以下是输出。图 1-2 未居中。我该如何解决这个问题?如果您能帮助我解决这个问题,我将不胜感激。
答案1
stikzpicture
是居中。在第二个图中,边界框不对称于原点。可以扩展边界框使其对称。(抱歉删除了中文字符,我的编辑器无法处理它们。)
\documentclass{book}
\usepackage[margin=2cm]{geometry}
\usepackage[cam,a4,center,noinfo]{crop}
\usepackage{tikz}
\usetikzlibrary{angles,calc,intersections,quotes}
\usepackage{caption}
\captionsetup[figure]{name=fig}
\renewcommand\thefigure{\thechapter-\arabic{figure}}
\begin{document}
\chapter{Test}
\begin{center}
\begin{tikzpicture}[scale=1.2]
\draw [gray] (0,0) circle [radius=2cm];
\fill (0,0) circle [radius=1pt];
\coordinate [label=left:$A$] (A) at (195:2cm);
\coordinate [label=left:$B$] (B) at (125:2cm);
\coordinate [label=right:$C$] (C) at (55:2cm);
\coordinate [label=right:$D$] (D) at (-15:2cm);
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\pic [draw,angle radius=3mm] {angle = A--B--C};
\pic [draw,angle radius=3mm] {angle = B--C--D};
\draw (current bounding box.south west)
-- node[midway]{$\times$} (current bounding box.south east) ;
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\draw (-3.5,0) -- (3.5,0) coordinate (x axis);
\draw (0,-3.5) -- (0,3.5) coordinate (y axis);
\draw [gray] (0,0) coordinate (O) circle [radius=3cm];
\path [name path=upward line] (3,0) coordinate (B) -- (3,3);
\path [name path=sloped line] (O) -- (30:6cm);
\path [name intersections={of=upward line and sloped line, by=C}];
\draw (C) node [above right,inner sep=1pt] {$C$} -- (O) node [below left,inner sep=1pt] {$O$}; %CO
\draw (C) -- node [right,inner sep=1pt] {$\tan x$} (B) node [below right,inner sep=1pt] {$B$}; %CB, tanx
\pic [draw,angle radius=1.5mm] {right angle = x axis--B--C}; %CB__x axis
\coordinate (A) at (30:3cm);
\coordinate (D) at (A|-x axis);
\draw (A) node [above,xshift=2pt,yshift=1pt] {$A$} -- node [left,inner sep=1pt] {$\sin x$} (D) node [below,inner sep=1pt] {$D$}; %AD, sinx
\pic [draw,angle radius=1.5mm] {right angle = x axis--D--A}; %AD__x axis
\draw (A) -- (B); %AB
\path (O) -- node [above] {$1$} (A);
\pic [draw,angle radius=5mm,angle eccentricity=1.5,"$x$"] {angle = B--O--A};
\node [right,inner sep=1pt] at (25:3cm) {$x$};
\draw (current bounding box.south west)
-- node[midway]{$\times$} (current bounding box.south east) ;
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\draw (-3.5,0) -- (3.5,0) coordinate (x axis);
\draw (0,-3.5) -- (0,3.5) coordinate (y axis);
\draw [gray] (0,0) coordinate (O) circle [radius=3cm];
\path [name path=upward line] (3,0) coordinate (B) -- (3,3);
\path [name path=sloped line] (O) -- (30:6cm);
\path [name intersections={of=upward line and sloped line, by=C}];
\draw (C) node [above right,inner sep=1pt] {$C$} -- (O) node [below left,inner sep=1pt] {$O$}; %CO
\draw (C) -- node [right,inner sep=1pt] {$\tan x$} (B) node [below right,inner sep=1pt] {$B$}; %CB, tanx
\pic [draw,angle radius=1.5mm] {right angle = x axis--B--C}; %CB__x axis
\coordinate (A) at (30:3cm);
\coordinate (D) at (A|-x axis);
\draw (A) node [above,xshift=2pt,yshift=1pt] {$A$} -- node [left,inner sep=1pt] {$\sin x$} (D) node [below,inner sep=1pt] {$D$}; %AD, sinx
\pic [draw,angle radius=1.5mm] {right angle = x axis--D--A}; %AD__x axis
\draw (A) -- (B); %AB
\path (O) -- node [above] {$1$} (A);
\pic [draw,angle radius=5mm,angle eccentricity=1.5,"$x$"] {angle = B--O--A};
\node [right,inner sep=1pt] at (25:3cm) {$x$};
\path let \p1=($(O)-(current bounding box.south
west)$),\p2=($(current bounding box.south east)-(O)$)
in ([xshift=-\x2]O) ([xshift=\x1]O);
\draw (current bounding box.south west)
-- node[midway]{$\times$} (current bounding box.south east) ;
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\end{document}
您可以在这里看到第二张图片中的边界框的水平中心不在原点下方。
在这里我们扩展了边界框,使其变得对称。
当然,
\draw (current bounding box.south west)
-- node[midway]{$\times$} (current bounding box.south east) ;
仅用于说明目的,最终需要从实际文档中删除。
**附录*:Henri Menke 指出,边界框不对称的原因之一是包含 的节点$\tan x$
。然而,“罪魁祸首”是你用于交叉的辅助线,
\path [name path=sloped line] (O) -- (30:6cm);
如果你将其替换为
\path [name path=sloped line,overlay] (O) -- (30:6cm);
按照亨利的建议,你会得到
\documentclass[tikz]{standalone}
\usetikzlibrary{angles,calc,intersections,quotes}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\draw (-3.5,0) -- (3.5,0) coordinate (x axis);
\draw (0,-3.5) -- (0,3.5) coordinate (y axis);
\draw [gray] (0,0) coordinate (O) circle [radius=3cm];
\path [name path=upward line] (3,0) coordinate (B) -- (3,3);
\path [name path=sloped line,overlay] (O) -- (30:6cm);
\path [name intersections={of=upward line and sloped line, by=C}];
\draw (C) node [above right,inner sep=1pt] {$C$} -- (O) node [below left,inner sep=1pt] {$O$}; %CO
\draw (C) -- node [right,inner sep=1pt,overlay] {$\tan x$} (B) node [below right,inner sep=1pt] {$B$}; %CB, tanx
\pic [draw,angle radius=1.5mm] {right angle = x axis--B--C}; %CB__x axis
\coordinate (A) at (30:3cm);
\coordinate (D) at (A|-x axis);
\draw (A) node [above,xshift=2pt,yshift=1pt] {$A$} -- node [left,inner sep=1pt] {$\sin x$} (D) node [below,inner sep=1pt] {$D$}; %AD, sinx
\pic [draw,angle radius=1.5mm] {right angle = x axis--D--A}; %AD__x axis
\draw (A) -- (B); %AB
\path (O) -- node [above] {$1$} (A);
\pic [draw,angle radius=5mm,angle eccentricity=1.5,"$x$"] {angle = B--O--A};
\node [right,inner sep=1pt] at (25:3cm) {$x$};
\draw (current bounding box.south west)
-- node[midway]{$\times$} (current bounding box.south east) ;
\end{tikzpicture}
\end{document}
边界框也是对称的,但如果将图片放在其他物体旁边,它可能会与相邻的物体重叠。