为什么我精确计算后,最左边和最右边的表规则还是会出现小的间隙呢?

为什么我精确计算后,最左边和最右边的表规则还是会出现小的间隙呢?

我已经使用公式精确指定了每个表格单元格的宽度

##1\linewidth-2\tabcolsep-1.5\arrayrulewidth如以下代码片段所示:


\documentclass[dvips,dvipsnames,rgb]{book}

\usepackage[a4paper,margin=10mm,showframe]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{calc}
\usepackage{lscape}

\newcounter{No}
\renewcommand{\theNo}{\stepcounter{No}\arabic{No}}
\newenvironment{MyTable}[4]%
{%
    \newcolumntype{A}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%
    \setcounter{No}{0}%comment out this if you want to continuous numbering for all tables.
    \begin{longtable}%
    {%
            |>{\scriptsize\centering\theNo}A{#1}<{}%
            |>{}A{#2}<{\centering\input{\jobname.tmp}}%
            |>{\centering\lstinputlisting{\jobname.tmp}}A{#3}<{}%
            |>{\scriptsize}A{#4}<{}%
            |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\newcommand{\Comment}[1]{& & & #1\tabularnewline\hline}


\usepackage{listings}
\lstset{%
language={PSTricks},
basicstyle=\ttfamily\scriptsize,%
keywordstyle=\color{blue}%,
%backgroundcolor=\color{yellow!30}%
}
\usepackage{fancyvrb}


\def\MyRow{%        
        \VerbatimEnvironment%
        \begin{VerbatimOut}{\jobname.tmp}%
}

\def\endMyRow{%
        \end{VerbatimOut}%      
}



\usepackage{pstricks,pst-node}
\newpsstyle{gridstyle}{%
gridwidth=0.4pt,%default: 0.8pt
gridcolor=Red!20,%default: black
griddots=0,%default: 0 
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=Blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=Green!20,%default: gray
subgriddots=0%default: 0
}

\usepackage{lipsum}

\begin{document}
%\clearpage
%\pagestyle{empty}
%Landscape starts here.
%\begin{landscape}
\begin{MyTable}{0.05}{.25}{0.4}{0.3}%
%=============
\begin{MyRow}
\pspicture*[showgrid](4,4)
\pnode(1,1){A}
\pnode(3,3){B}
\ncline{A}{B}
\endpspicture
\end{MyRow}
\Comment{\lipsum[1]}
%=============
\begin{MyRow}
\begin{pspicture}[showgrid](4,3)
\psframe*[linecolor=red!30](3,2)
\end{pspicture}
\end{MyRow}
\Comment{\lipsum[2]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=green!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[3]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=yellow!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[4]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=Maroon!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[5]}
%=============
\end{MyTable}
%\end{landscape}
%Landscape stops here.
%\pagestyle{plain}
\end{document}

如果我放大输出,我将得到以下结果:

桌子最左边有一个空隙:

替代文本


最右边的桌子边缘也有一个空隙:

替代文本


我认为这是由于 LaTeX 引擎的四舍五入造成的。有办法解决这个问题吗?


编辑1:

你可能会想,为什么我坚持要得到最完美的输出。因为我想用这个表格布局创建一个“气泡”答题纸。因此,高精度布局是必须的。:-)

答案1

我找到解决办法了。:-)

\documentclass[dvips,dvipsnames,rgb]{book}

\usepackage[a4paper,hmargin=10mm,vmargin=40mm,showframe]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{calc}
\usepackage{lscape}
\setlength{\tabcolsep}{2mm}
\setlength{\arrayrulewidth}{2mm}
\newcounter{No}
\renewcommand{\theNo}{\stepcounter{No}\arabic{No}}
\newenvironment{MyTable}[4]%
{%
    \newcolumntype{O}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%
    \newcolumntype{I}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    ##1\linewidth-2\tabcolsep-\arrayrulewidth%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%
    \setcounter{No}{0}%comment out this if you want to continuous numbering for all tables.
    \begin{longtable}%
    {%
            |>{\scriptsize\centering\theNo}O{#1}<{}%
            |>{}I{#2}<{\centering\input{\jobname.tmp}}%
            |>{\centering\lstinputlisting{\jobname.tmp}}I{#3}<{}%
            |>{\scriptsize\bgroup\color{black}}O{#4}<{\egroup}%
            |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\newcommand{\Comment}[1]{&&&#1\tabularnewline\hline}


\usepackage{listings}
\lstset{%
language={PSTricks},
breaklines=true,
basicstyle=\ttfamily\scriptsize,%
keywordstyle=\color{blue},
backgroundcolor=\color{yellow!30}%
}
\usepackage{fancyvrb}


\def\MyRow{%        
        \VerbatimEnvironment%
        \begin{VerbatimOut}{\jobname.tmp}%
}

\def\endMyRow{%
        \end{VerbatimOut}%      
}



\usepackage{pstricks,pst-node}
\newpsstyle{gridstyle}{%
gridwidth=0.4pt,%default: 0.8pt
gridcolor=Red!20,%default: black
griddots=0,%default: 0 
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=Blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=Green!20,%default: gray
subgriddots=0%default: 0
}

\usepackage{lipsum}

\begin{document}
\color{red}%
%\clearpage
%\pagestyle{empty}
%Landscape starts here.
%\begin{landscape}
\begin{MyTable}{0.05}{0.3}{0.3}{0.35}%
%=============
\begin{MyRow}
\pspicture*[showgrid](3,3)
\pnode(1,1){A}
\pnode(3,3){B}
\ncline{A}{B}
\endpspicture
\end{MyRow}
\Comment{\lipsum[1]}
%=============
\begin{MyRow}
\begin{pspicture}[showgrid](3,3)
\psframe*[linecolor=red!30](3,2)
\end{pspicture}
\end{MyRow}
\Comment{\lipsum[2]}
%=============
\begin{MyRow}
\pspicture[showgrid](3,3)
\psframe*[linecolor=green!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[3]}
%=============
\begin{MyRow}
\pspicture[showgrid](3,3)
\psframe*[linecolor=yellow!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[4]}
%=============
\begin{MyRow}
\pspicture[showgrid](3,3)
\psframe*[linecolor=Maroon!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[5]}
%=============
\end{MyTable}
%\end{landscape}
%Landscape stops here.
%\pagestyle{plain}
\end{document}

对于最左边或最右边的列,前面的公式##1\linewidth-2\tabcolsep-1.5\arrayrulewidth适用。

但对于剩余的列,正确的公式是##1\linewidth-2\tabcolsep-\arrayrulewidth。:-)

相关内容