我想使用下面写的代码将图形和表格并排放置在单列文档中。我面临两个问题:1. 表格超出边距,我无法缩小它。2. 图形和表格没有并排对齐请提出修改代码的建议。
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows,
chains,% <--- new\frac{•}{•}
decorations.markings,
shadows, shapes.arrows}
\tikzset{% <--- modified
decision/.style = {diamond,draw, fill=blue!50},
line/.style = {draw, -stealth, thick},
block/.style = {rectangle, draw, text width=4 em, minimum height=10 mm,
align=center}
}
\begin{document}
\begin{minipage}{\textwidth}
\begin{minipage}[b]{0.49\textwidth}
\centering
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=0.5]
\tikzstyle{cir1} = [draw, circle, node distance=1.5cm,scale=1]
\draw (-4,0) -- (4,0);
\draw (0,-4) -- (0,4);
\draw (-2,2) node[ cir1 , label=above:f] {};
\draw (2,2) node[ cir1 , label=above:e] {};
\draw (-2,-2) node[ cir1 ,label=above:c] {};
\draw (2,-2) node[ cir1 , label=above:d] {};
\draw ({2} ,0) node[cir1 , fill=black,label=above:b] {};
\draw (-{2} ,0) node[cir1 , fill=black,label=above:a] {};
\end{tikzpicture}
\end{minipage}
\hfill
\begin{minipage}[t]{0.49\textwidth}
\centering
\begin{tabular}{|c|c|c|}
\hline
{\footnotesize Original Symbol} & {\footnotesize Mapped Symbol}& {\footnotesize Mapped Symbol}\\
& {\footnotesize (1D Mapping)}&{\footnotesize ( 2D Mapping)}\\
\hline
a & With same real part (c or f) & c or e \\
& With same imaginary part (f or e ) & d or f \\
\hline
\end{tabular}
\end{minipage}
\end{minipage}
\end{document}
答案1
tikzpicture
等tabular
没有特殊的定位规则,它们就像大写字母一样被处理,如果彼此相邻,它们会并排排列。如果它们之间有间距,它们会形成一个段落,该段落可能位于一行或两行,具体取决于行数。
因此,您可以删除所有的小页面,然后如果它们足够小的话,它们就可以放在一行上。
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows,
chains,% <--- new\frac{•}{•}
decorations.markings,
shadows, shapes.arrows}
\tikzset{% <--- modified
decision/.style = {diamond,draw, fill=blue!50},
line/.style = {draw, -stealth, thick},
block/.style = {rectangle, draw, text width=4 em, minimum height=10 mm,
align=center}
}
\begin{document}
\begin{center}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=0.5,align=center]
\tikzstyle{cir1} = [draw, circle, node distance=1.5cm,scale=1]
\draw (-4,0) -- (4,0);
\draw (0,-4) -- (0,4);
\draw (-2,2) node[ cir1 , label=above:f] {};
\draw (2,2) node[ cir1 , label=above:e] {};
\draw (-2,-2) node[ cir1 ,label=above:c] {};
\draw (2,-2) node[ cir1 , label=above:d] {};
\draw ({2} ,0) node[cir1 , fill=black,label=above:b] {};
\draw (-{2} ,0) node[cir1 , fill=black,label=above:a] {};
\end{tikzpicture}%
\footnotesize
\begin{tabular}[b]{@{}|c|c|c|@{}}
\hline
Original & Mapped Symbol& Mapped Symbol\\
Symbol & (1D Mapping)& ( 2D Mapping\\
\hline
a & Same real part (c or f) & c or e \\
& Same imaginary part (f or e ) & d or f \\
\hline
\end{tabular}
\end{center}
\end{document}
答案2
tabularx
除了使用小页面之外,您还可以使用带有嵌套的单一环境tabular
:
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{makecell, tabularx} %
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,
chains,% <--- new\frac{•}{•}
decorations.markings,
shadows, shapes.arrows}
\tikzset{% <--- modified
decision/.style = {diamond,draw, fill=blue!50},
line/.style = {draw, -stealth, thick},
block/.style = {rectangle, draw, text width=4 em, minimum height=10 mm,
align=center}
}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{>{\centering}Xc}
\raisebox{-0.5\height}{\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=0.5]
\tikzstyle{cir1} = [draw, circle, node distance=1.5cm,scale=1]
\draw (-4,0) -- (4,0);
\draw (0,-4) -- (0,4);
\draw (-2,2) node[ cir1 , label=above:f] {};
\draw (2,2) node[ cir1 , label=above:e] {};
\draw (-2,-2) node[ cir1 ,label=above:c] {};
\draw (2,-2) node[ cir1 , label=above:d] {};
\draw ({2} ,0) node[cir1 , fill=black,label=above:b] {};
\draw (-{2} ,0) node[cir1 , fill=black,label=above:a] {};
\end{tikzpicture}} &\footnotesize
\begin{tabular}{|c|c|c|}
\hline
Original Symbol & Mapped Symbol & Mapped Symbol \\
& (1D Mapping)& ( 2D Mapping)\\
\hline
a & \makecell[l]{With same real part \\(c or f)} & c or e \\[3ex]
& \makecell[l]{With same imaginary\\ part (f or e) } & d or f \\
\hline
\end{tabular}
\end{tabularx}
\end{document}
通过重新设计的表格,我们可以得到更大的数字:
\documentclass[12pt, a4paper]{article}
\usepackage{graphicx}
\usepackage{makecell, tabularx} %
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,
chains,% <--- new\frac{•}{•}
decorations.markings,
shadows, shapes.arrows}
\tikzset{% <--- modified
decision/.style = {diamond,draw, fill=blue!50},
line/.style = {draw, -stealth, thick},
block/.style = {rectangle, draw, text width=4 em, minimum height=10 mm,
align=center}
}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{>{\centering}Xc}
\raisebox{-0.5\height}{\begin{tikzpicture}[auto, node distance=2cm,>=latex',scale=0.8]
\tikzstyle{cir1} = [draw, circle, node distance=1.5cm,scale=1]
\draw (-4,0) -- (4,0);
\draw (0,-4) -- (0,4);
\draw (-2,2) node[ cir1 , label=above:f] {};
\draw (2,2) node[ cir1 , label=above:e] {};
\draw (-2,-2) node[ cir1 ,label=above:c] {};
\draw (2,-2) node[ cir1 , label=above:d] {};
\draw ({2} ,0) node[cir1 , fill=black,label=above:b] {};
\draw (-{2} ,0) node[cir1 , fill=black,label=above:a] {};
\end{tikzpicture}} &\footnotesize\setlength\extrarowheight{2pt}
\setlength\tabcolsep{4pt}
\begin{tabular}{|l|c|c|}
\hline
Original Symbol & \multicolumn{2}{c|}{a}\\
\hline
Mapped Symbol & \makecell{With same\\ real part} & \makecell{With same\\ imaginary part }\\
\hline
(1D Mapping) & (c or f) & (f or e) \\
(2D Mapping) & c or e & d or f\\
\hline
\end{tabular}
\end{tabularx}
\end{document}