如何在表格单元格中设置 4 个相等的填充(左、右、上、下)?

如何在表格单元格中设置 4 个相等的填充(左、右、上、下)?

我希望表格中的每个单元格都有 4 个相等的填充,每个填充正好是 15pt。

如何在表格单元格中设置 4 个相等的填充(左、右、上、下)?

\documentclass{article}
\usepackage{array,calc,longtable,ragged2e,pstricks}
\psset{linecolor=red}
\tabcolsep=1pt
\arrayrulewidth=1pt

\newcolumntype{A}[1]{>{\Centering}m{#1\linewidth-2\tabcolsep-1.5\arrayrulewidth}}

\def\pic{\begin{pspicture}(4,3)\psframe*(4,3)\end{pspicture}}

\begin{document}
\begin{longtable}{|*2{A{0.5}|}}\hline
\pic&\pic\tabularnewline\hline
\end{longtable}
\end{document}

替代文本


下面的 Herbert 解决方案显然不支持显示方程。请使用xelatex或进行编译latex-dvips-ps2pdf

\documentclass{article}
\usepackage{array,amsmath,longtable,ragged2e,pst-node,varwidth}
\psset{linecolor=blue}
\tabcolsep=1pt
\arrayrulewidth=1pt
\newsavebox\TBox

\def\picB{\begin{pspicture}(4,3)\psframe*(4,3)\end{pspicture}}

\newenvironment{saveTBox}
  {\begin{lrbox}{\TBox}\varwidth{\linewidth}}
  {\endvarwidth\end{lrbox}%
   \fboxrule=0pt\fboxsep=15pt\fbox{\usebox\TBox}}

\newcolumntype{B}{@{}>{\saveTBox}c<{\endsaveTBox}@{}}

\begin{document}

\begin{longtable}{|B|B|B|}\hline
    \[\rnode[r]{A}{y=f(x)}\] & \rnode[l]{B}{$\displaystyle y=f(x)$} & \picB 
    \ncline{A}{B}\tabularnewline\hline
\end{longtable}

\end{document}

在此处输入图片描述

答案1

与允许显示方程式相同......

\documentclass{article}
\usepackage{array,amsmath,longtable,ragged2e,pstricks,varwidth}
\psset{linecolor=red}
\tabcolsep=1pt
\arrayrulewidth=1pt
\newsavebox\TBox

\def\picB{\begin{pspicture}(4,3)\psframe*(4,3)\end{pspicture}}

\newenvironment{saveTBox}
  {\begin{lrbox}{\TBox}\varwidth{\linewidth}}
  {\endvarwidth\end{lrbox}%
   \fboxrule=0pt\fboxsep=15pt\fbox{\usebox\TBox}}

\newcolumntype{B}{@{}>{\saveTBox}c<{\endsaveTBox}@{}}

\begin{document}

\begin{longtable}{|B|B|}\hline
\[ y=f(x) \] & \picB      
  \tabularnewline\hline
\end{longtable}

\end{document}

答案2

您可以使用以下方法在四边用给定的内边距包围水平材料,而不更改其基线。在表格中使用它应该会得到所需的结果,但您必须确保表格环境不会插入一些额外的内边距。

\def\padded#1#2{%
   \setbox0\hbox{#2}%
   \dimen0=\dp0
   \setbox2\hbox{\hskip #1\vbox{\vskip #1\box0\vskip#1}\hskip#1}%
   \advance\dimen0 by #1%
   \leavevmode\lower\dimen0\box2}

您可以将其用作\padded{10pt}{Blah pjqy}

答案3

\documentclass{article}
\usepackage{array,calc,longtable,ragged2e,pstricks}
\psset{linecolor=red}
\tabcolsep=1pt
\arrayrulewidth=1pt
\newsavebox\TBox

\def\pic{\begin{pspicture}(-5mm,-5mm)(4.5,3.5)\psframe*(4,3)\end{pspicture}}
\def\picB{\begin{pspicture}(4,3)\psframe*(4,3)\end{pspicture}}

\begin{document}
\begin{longtable}{| c | c|}\hline
\pic&\pic\tabularnewline\hline
\end{longtable}

 \fboxrule=0pt\fboxsep=15pt
\begin{longtable}{| c | c|}\hline
\savebox\TBox{$\frac{x^2}{1+2x^2}$}\fbox{\usebox\TBox} & foo \tabularnewline\hline
\end{longtable}


\newenvironment{saveTBox}
  {\fboxrule=0pt\fboxsep=15pt%
   \begin{lrbox}{\TBox}}
  {\end{lrbox}\fbox{\usebox\TBox}}

\newcolumntype{B}{>{\saveTBox}c<{\endsaveTBox}}

\tabcolsep=0pt
\begin{longtable}{| B|B |}\hline
\picB & \picB\tabularnewline\hline
\end{longtable}

\end{document}

答案4

使用 XeTeX 的 Plain 版本:

{
  \newskip\tableverticalpadding   \tableverticalpadding=1cm
  \newskip\tablehorizontalpadding \tablehorizontalpadding=1cm
  % Those are glues, by the way
  \everycr={\noalign{\vskip\tableverticalpadding}}
  \tabskip=\tablehorizontalpadding
  \vbox{% Just for the \hrule's
    \hrule height 1pt
    \halign{&\hfil$\vcenter{\hbox{#}}$\hfil\cr % horizontal/vertical centered
      Column with text&\XeTeXpicfile "i-stress-test.jpg" \cr
      \XeTeXpicfile "test-pattern.jpg" &\vbox{$$\sum^{\infty}_{i=1} math$$}\cr % added vbox around $$
    }
    \hrule height 1pt
  }
}
\bye

在此处输入图片描述

相关内容