如何制作如图所示的两个正方形和两条垂直线?
\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{graphicx}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{booktabs,array,tabularx}
\usepackage{siunitx, makecell}
\usepackage{mathtools,float}
\usepackage{indentfirst}
\usepackage{multirow}
\usepackage{float}
\renewcommand*{\arraystretch}{1.5}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc, fit, positioning}
\usetikzlibrary{shapes}
\usepackage{diagbox}
\allowdisplaybreaks[3]
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|cccc|}
\hline
\backslashbox{I5 I10}{Q1 Q0} & 00 & 01 & 11 & 10\\
\hline
00 & 0& 1 & 0 & 0 \\
01 & 0& 1 & 0 & 1\\
11 & x& x & x & x\\
10 & 1& 0 & 1 & 1\\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
像这样吗?
\documentclass[11pt, a4paper, svgnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{multirow, float}
\usepackage{diagbox}
\usepackage{pst-node, auto-pst-pdf}
\begin{document}
\begin{table}[H]
\centering\setlength\extrarowheight{3pt}
\begin{postscript}
\begin{tabular}{|c|cccc|}
\hline
\backslashbox{I5 I10}{Q1 Q0} & 00 & 01 & 11 & 10\\
\hline
00 & 0& 0 & \Rnode{T}{1} & 0\\
01 & 0& 0 & 1 & 0\\
11 & x& x & x & x\\
10 & 0& 0 & \Rnode{B}{1} & 0\\
\hline
\end{tabular}
\ncbox[linejoin =1, nodesep=0.5ex, boxsize=0.25, linecolor=IndianRed]{T}{B}
\end{postscript}
\end{table}
\end{document}
答案2
您tikz
还可以选择周围边框的形状,这里有两个示例,带有ellipse
和rectangle
带有rounded borders
。
我还冒昧地建议了另一种格式化表格的方法。
\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{multirow}
\usepackage{diagbox}
\usepackage{float}
\renewcommand*{\arraystretch}{1.5}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc, fit, positioning}
\usetikzlibrary{shapes}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|cccc|}
\hline
\backslashbox{I5 I10}{Q1 Q0} & 00 & 01 & 11 & 10\\
\hline
00 & 0& 0 & \tikzmark{fromhere}1 & 0\\
01 & 0& 0 & 1 & 0\\
11 & x& x & x & x\\
10 & 0& 0 & \tikzmark{tohere}1 & 0\\
\hline
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\node[ellipse, draw, blue, xshift=.27em, minimum width=1.5em,
fit={(pic cs:fromhere) (pic cs:tohere)}
] {};
\end{tikzpicture}
\end{table}
\begin{table}[H]
\centering
\begin{tabular}{*5c}
& \multicolumn{4}{c}{\textbf{Q1 Q0}}\\
\cline{2-5}
\textbf{I5 I10} & 00 & 01 & 11 & 10\\
\hline
00 & 0& 0 & \tikzmark{fromhereii}1 & 0\\
01 & 0& 0 & 1 & 0\\
11 & x& x & x & x\\
10 & 0& 0 & \tikzmark{tohereii}1 & 0\\
\hline
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\node[rectangle, rounded corners, draw, blue, xshift=.27em, minimum width=1.5em,
fit={($(pic cs:fromhereii)+(0,.25)$) (pic cs:tohereii)}
] {};
\end{tikzpicture}
\end{table}
\end{document}
编辑:问题新版本的答案
\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{graphicx}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{booktabs,array,tabularx}
\usepackage{siunitx, makecell}
\usepackage{mathtools,float}
\usepackage{indentfirst}
\usepackage{multirow}
\usepackage{float}
\renewcommand*{\arraystretch}{1.5}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc, fit, positioning}
\usetikzlibrary{shapes}
\usepackage{diagbox}
\allowdisplaybreaks[3]
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|cccc|}
\hline
\backslashbox{I5 I10}{Q1 Q0} & 00 & 01 & 11 & 10\\
\hline
00 & 0& \tikzmark{c23}1 & 0 & 0 \\
01 & 0& \tikzmark{c33}1 & 0 & \tikzmark{c35}1\\
11 & \tikzmark{c42}x& x & \tikzmark{c44}x & \tikzmark{c45}x\\
10 & \tikzmark{c52}1& 0 & \tikzmark{c54}1 & \tikzmark{c55}1\\
\hline
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\node[rectangle, rounded corners, draw, blue, xshift=0.27em, minimum width=1.5em, fit={($(pic cs:c44)+(-.15,.25)$)($(pic cs:c55)+(.15,-.04)$)} ] {};
\node[ellipse, draw, green, xshift=0.27em, minimum width=1.5em, fit={($(pic cs:c23)+(0,0.2)$)(pic cs:c33)} ] {};
\node[ellipse, draw, green, xshift=0.27em, minimum width=1.5em, fit={($(pic cs:c35)+(0,0.2)$)(pic cs:c45)} ] {};
\draw[dashed, very thick, rounded corners, red]($(pic cs:c42)+(-.1,0.4)$) -- ($(pic cs:c42)+(.4,0.4)$) -- ($(pic cs:c52)+(.4,-.15)$) -- ($(pic cs:c52)+(-.1,-.15)$);
\draw[dashed, very thick, rounded corners, red] ($(pic cs:c45)+(.4,0.4)$) -- ($(pic cs:c45)+(-.1,0.4)$) -- ($(pic cs:c55)+(-.1,-.15)$) -- ($(pic cs:c55)+(.4,-.15)$);
\end{tikzpicture}
\end{table}
\end{document}
第二次编辑:\tikzmark
解释
使用命令\tikzmark{<my_node_name>}
创建节点<my_node_name>
,并将其定位到您编写此命令的位置。
随着[overlay,remember picture]
你告诉你tikz
,你正在创建的图片必须写在你放置的位置\tikzmark
。
绘制\node[rectangle, rounded corners, draw, blue, xshift=0.27em, minimum width=1.5em, fit={($(pic cs:c44)+(-.15,.25)$)($(pic cs:c55)+(.15,-.04)$)} ] {};
一个蓝色矩形,带圆角,水平移动 0.27em,最小宽度为 1.5em,必须适合以下点:
- 节点坐标
c44
水平移动 -.15cm,垂直移动 .25cm - 节点坐标
c55
水平移动了.15cm,垂直移动了-.04cm。
\node[ellipse, draw, green, xshift=0.27em, minimum width=1.5em, fit={($(pic cs:c23)+(0,0.2)$)(pic cs:c33)} ] {};
绘制一个绿色椭圆,水平移动 0.27em,与以下点相符:
- 节点坐标
c23
垂直移动.2cm - 节点的坐标
c33
。
\draw[dashed, very thick, rounded corners, red]($(pic cs:c42)+(-.1,0.4)$) -- ($(pic cs:c42)+(.4,0.4)$) -- ($(pic cs:c52)+(.4,-.15)$) -- ($(pic cs:c52)+(-.1,-.15)$);
绘制一条非常粗的红线,带有圆角,穿过以下点:
- 节点坐标
c42
水平移动 -.1cm,垂直移动 .4cm - 节点坐标
c42
水平移动 0.4cm,垂直移动 0.4cm - 节点坐标
c52
水平移动.4cm,垂直移动-.15cm - 节点坐标
c52
水平移动-.1cm,垂直移动-.15cm。