与表格位置相关的图像位置

与表格位置相关的图像位置

位于同一 mdframe 内的图像和表格为何定位不同?如何解决?

此屏幕转储显示了该问题: 在此处输入图片描述

我原本希望它们都对齐在相同的位置(顶部、中间或底部),而不是不同。如何将它们全部对齐到顶部。以便表格的文本从图像的顶部开始?

使用代码示例进行更新

我尝试创建一个示例来说明我如何得到“错误”。我还发现了另一个相关问题,但我不知道如何将答案应用到我的解决方案中,因为它并不完全相同,但很接近。

代码示例有点长。不过,请尝试看一下方法profileImage开头使用的方法createPerson,该方法将图像和表格定位在里面mdFrame

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{tabularx}
\RequirePackage[framemethod=TikZ]{mdframed}
\usepackage{hyperref} 


\newsavebox\profileImageBox
\NewDocumentCommand{\profileImage}%
      {O{width=0.6\linewidth}
       O{draw=black,line width=0.75pt,rounded corners=6pt}
       m}{%
   \savebox\profileImageBox{\includegraphics[#1]{#3}}%
   \begin{tikzpicture}%
    \draw [path picture={%
                   \node at (path picture bounding box.center) {%
                       \usebox\profileImageBox};},#2]
          (0,0)  rectangle (\wd\profileImageBox,\ht\profileImageBox);
   \end{tikzpicture}%
}

\NewDocumentCommand\createPerson{r<>omomo+d<>}
{
    \begin{mdframed}[style=whiteBox]%
        \profileImage[width=0.25\textwidth]{#1}
        \begin{tabularx}{0.75\textwidth}{lXrc}%
            % Row one
            Navn:   &   \nameref{#3}    & #5    & $\Re$%
            %Create new row if needed
            \IfNoValueTF{#2}%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}}%
                        {\\}}%
                    {\\}}%
                {\\}%
            % Row two
            \IfNoValueTF{#4}%
                % If no birth name
                {\IfNoValueTF{#2}%
                    % If no called name
                    {&&}%
                    % If a called name
                    {Kaldenavn: & #2 &}}%
                %If a birth name
                {Fødenavn: & #4 &}%
                %
                \IfNoValueTF{#6}%
                       % If no birth date
                       {\IfNoValueTF{#7}{}{#7 & \cross}}%
                       {#6 & $\star$}%
            % Create new row if needed    
            \IfNoValueTF{#2}%
                {%
                \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                }%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                    }%
                    {\\}%
                }%
            % Row three
            \IfNoValueTF{#2}%
                % If no called name
                {%
                    \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {&&}%
                        }%
                }%
                % If a called name
                {\IfNoValueTF{#4}%
                    % If no birth name
                    {
                        \IfNoValueTF{#6}%
                            {}%
                            {\IfNoValueTF{#7}%
                                {}%
                                {&&}%
                            }%
                    }%
                    %If birth name
                    {Kaldenavn: & #2 &}%
                }%
            %
            \IfNoValueTF{#7}%
                       % If no death date
                       {}%
                       {\IfNoValueTF{#6}{}{#7 & \cross}}%
        \end{tabularx}%
    \end{mdframed}%
}

\newcommand{\cross}[1][.7pt]{\ooalign{%
  \rule[1ex]{1ex}{#1}\cr% Horizontal bar
  \hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}

\begin{document}

    \section{Edith Marie Larsen}
    \label{EdithMariePetersen1900}


    \createPerson%
        <woman.jpg>%
        [Edith]%
        {EdithMariePetersen1900}%
        [Edith Marie Petersen]%
        {15}%
        [2. okt. 1900]%
        <9. jul. 1970>%

\end{document}

答案1

你必须使用

\begin{tabularx}{0.75\textwidth}[t]{lXrc}

用于顶部对齐表格并向下移动图片;一种简单的方法是adjustbox

\begin{adjustbox}{valign=t}
<tikzpicture>
\end{adjustbox}

完整示例:

\documentclass{article}
\usepackage{xparse}
\usepackage{adjustbox}
\usepackage{tikz}
\usepackage{tabularx}
\RequirePackage[framemethod=TikZ]{mdframed}
\usepackage{hyperref} 


\newsavebox\profileImageBox
\NewDocumentCommand{\profileImage}%
      {O{width=0.6\linewidth}
       O{draw=black,line width=0.75pt,rounded corners=6pt}
       m}{%
   \savebox\profileImageBox{\includegraphics[#1]{#3}}%
   \begin{adjustbox}{valign=t}
   \begin{tikzpicture}%
    \draw [path picture={%
                   \node at (path picture bounding box.center) {%
                       \usebox\profileImageBox};},#2]
          (0,0)  rectangle (\wd\profileImageBox,\ht\profileImageBox);
   \end{tikzpicture}%
   \end{adjustbox}%
}

\NewDocumentCommand\createPerson{r<>omomo+d<>}
{
    \begin{mdframed}[style=whiteBox]%
        \profileImage[width=0.25\textwidth]{#1}
        \begin{tabularx}{0.75\textwidth}[t]{lXrc}%
            % Row one
            Navn:   &   \nameref{#3}    & #5    & $\Re$%
            %Create new row if needed
            \IfNoValueTF{#2}%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}}%
                        {\\}}%
                    {\\}}%
                {\\}%
            % Row two
            \IfNoValueTF{#4}%
                % If no birth name
                {\IfNoValueTF{#2}%
                    % If no called name
                    {&&}%
                    % If a called name
                    {Kaldenavn: & #2 &}}%
                %If a birth name
                {Fødenavn: & #4 &}%
                %
                \IfNoValueTF{#6}%
                       % If no birth date
                       {\IfNoValueTF{#7}{}{#7 & \cross}}%
                       {#6 & $\star$}%
            % Create new row if needed    
            \IfNoValueTF{#2}%
                {%
                \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                }%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                    }%
                    {\\}%
                }%
            % Row three
            \IfNoValueTF{#2}%
                % If no called name
                {%
                    \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {&&}%
                        }%
                }%
                % If a called name
                {\IfNoValueTF{#4}%
                    % If no birth name
                    {
                        \IfNoValueTF{#6}%
                            {}%
                            {\IfNoValueTF{#7}%
                                {}%
                                {&&}%
                            }%
                    }%
                    %If birth name
                    {Kaldenavn: & #2 &}%
                }%
            %
            \IfNoValueTF{#7}%
                       % If no death date
                       {}%
                       {\IfNoValueTF{#6}{}{#7 & \cross}}%
        \end{tabularx}%
    \end{mdframed}%
}

\newcommand{\cross}[1][.7pt]{\ooalign{%
  \rule[1ex]{1ex}{#1}\cr% Horizontal bar
  \hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}

\begin{document}

    \section{Edith Marie Larsen}
    \label{EdithMariePetersen1900}


    \createPerson%
        <../duck.jpg>%
        [Edith]%
        {EdithMariePetersen1900}%
        [Edith Marie Petersen]%
        {15}%
        [2. okt. 1900]%
        <9. jul. 1970>%

\end{document}

在此处输入图片描述

带有七个参数和各种分隔符的命令当然应该用单个键值参数来处理。

相关内容