编辑

编辑

黑色 tikz 框/节点未在单元格内垂直对齐。有人知道该怎么做吗?提前谢谢,请忽略不相关的代码,我知道它不是很干净或直接!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usepackage{multirow}
\usepackage{arydshln}

\begin{document}

\newcommand{\especialidade}[1]{\tikzstyle{block} = [rectangle, fill=black, 
    text width=0.25\columnwidth, text depth=0mm, text centered, text height=0.30cm, rounded corners]
    \begin{tikzpicture}[node distance = 1cm, auto]
    \node [block] (init) {\textcolor{white}{\textbf{#1}}};
    \end{tikzpicture}}

\begin{table}[h!]
\makebox[\linewidth]{
{\renewcommand{\arraystretch}{2}
\setlength{\arrayrulewidth}{0.5mm}
\setlength\tabcolsep{1mm}
\begin{tabular}{
    p{0.22\linewidth} p{0\linewidth};{0.5mm/2pt} @{\linethickness{0.2mm}\framebox(10,10){}\hspace{3mm}}
    p{0.23\linewidth} p{0\linewidth};{0.5mm/2pt} @{\linethickness{0.2mm}\framebox(10,10){}\hspace{3mm}}
    p{0.23\linewidth} p{0\linewidth};{0.5mm/2pt} @{\linethickness{0.2mm}\framebox(10,10){}\hspace{3mm}}
    p{0.24\linewidth} p{0\linewidth} @{\linethickness{0.2mm}\framebox(10,10){}\hspace{3mm}}}

\hline\multicolumn{2}{p{0.23\linewidth};{0.5mm/2pt}}{\especialidade{AAA \textsuperscript{A}}}& \hspace{1mm}
AA (111) &&
\multicolumn{2}{p{0.23\linewidth};{0.5mm/2pt}}{\especialidade{AAA \textsuperscript{A}}}&\hspace{1mm}
Aaaa-\textit{Aaaa} (111)& \\\hline

Aaaaaaa (111) &&\hspace{1mm}
Aaaaaaa (111) &&\hspace{1mm}
AA aaaaa (111) &&\hspace{1mm}
Aaaa-\textit{aaa} (111)& \\
\end{tabular}
}
}
\end{table}
\end{document}

答案1

array包提供了一个m{}列说明符,它与 类似p{},不同之处在于,p{}它将单元格内容放在顶部对齐\parbox[t]{}{}\m{}而将其放在中间对齐\parbox[c]{}{}。例如:

\documentclass{article}
\usepackage{array}
\begin{document}
  \begin{tabular}{p{.25\linewidth}cm{.25\linewidth}}
    this is a very long line of text in a top-aligned parbox & this is horizontally centred & this is a very long line of text in a centre-aligned parbox\\
  \end{tabular}
\end{document}

顶部和中心对齐的列

请不要依赖tabu。如果你想使用它,即使它可能会出乎意料地破坏你,那也没关系。但要明白,只有当新版本破坏你的文档时,才会修复一些错误。

编辑

在这种情况下,您会遇到由超大内容(不是常规文本)引起的复杂情况。对于空框,您可以使用\raisebox,我过去常常-2.5pt将框向下移动一点。根据需要进行调整。对于 TikZ 图片,您可以使用调整相对于基线的图片baseline。在这里,我使用了baseline=(init.base)。同样,根据需要进行调整。我还更新了代码以使用新语法\tikzset{}而不是弃用的\tikzstyle{}

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usepackage{multirow}
\usepackage{arydshln}

\begin{document}

\newcommand{\especialidade}[1]{%
  \tikzset{
    block/.style = {
      rectangle,
      fill=black,
      text width=0.25\columnwidth,
      text depth=0mm,
      text centered,
      text height=0.30cm,
      rounded corners
    }
  }%
    \begin{tikzpicture}[node distance = 1cm, auto, baseline=(init.base)]
    \node [block] (init) {\textcolor{white}{\textbf{#1}}};
    \end{tikzpicture}}

\newsavebox{\mybox}
\sbox\mybox{%
  \raisebox{-2.5pt}{\linethickness{0.2mm}\framebox(10,10){}\hspace{3mm}}}

\begin{table}[h!]
\makebox[\linewidth]{
{\renewcommand{\arraystretch}{2}
\setlength{\arrayrulewidth}{0.5mm}
\setlength\tabcolsep{1mm}
\begin{tabular}{
    m{0.22\linewidth} m{0\linewidth};{0.5mm/2pt} @{\usebox{\mybox}}
    m{0.23\linewidth} m{0\linewidth};{0.5mm/2pt} @{\usebox{\mybox}}
    m{0.23\linewidth} m{0\linewidth};{0.5mm/2pt} @{\usebox{\mybox}}
    m{0.24\linewidth} m{0\linewidth} @{\usebox{\mybox}}}

\hline\multicolumn{2}{m{0.23\linewidth};{0.5mm/2pt}}{\especialidade{AAA \textsuperscript{A}}}& \hspace{1mm}
AA (111) &&
\multicolumn{2}{m{0.23\linewidth};{0.5mm/2pt}}{\especialidade{AAA \textsuperscript{A}}}&\hspace{1mm}
Aaaa-\textit{Aaaa} (111)& \\\hline

Aaaaaaa (111) &&\hspace{1mm}
Aaaaaaa (111) &&\hspace{1mm}
AA aaaaa (111) &&\hspace{1mm}
Aaaa-\textit{aaa} (111)& \\
\end{tabular}
}
}
\end{table}
\end{document}

调整后的框和图片

但是使用和调整基线的基本思想m{}与上面的更简单的例子相同。

答案2

尝试使用:

\newcommand{\especialidade}[1]{\tikzstyle{block} = [rectangle, fill=black,
    text width=0.2\columnwidth, text depth=0mm, text centered, text height=0.30cm, rounded corners]
    \begin{tikzpicture}[baseline=(init.base)]
    \node [block] (init) {\textcolor{white}{\textbf{#1}}};
    \end{tikzpicture}}

而不是你的newcomand

编辑:稍微修改一下你的命令(它给出相同的结果):

\newcommand{\especialidade}[1]{
    \begin{tikzpicture}[baseline=(init.base),%this determine where is baseline
    block/.style = {rectangle, fill=black, rounded corners,
                    text width=0.22\columnwidth, text depth=0mm, text height=0.30cm, 
                    font=\bfseries, align=center}]
    \node [block] (init) {\textcolor{white}{#1}};
    \end{tikzpicture}}

相关内容