tabularx 环境中等距、等大小的数字

tabularx 环境中等距、等大小的数字

目前我通过 来实现4个不同图形的相同尺寸\includegraphics[width=0.197\linewidth]{example-image-a}

在此处输入图片描述

但是,它0.197是硬编码的,因此不够优雅。

还有更多吗动态的实现期望输出的方法?

请参阅我的 MWE:

\documentclass[10pt, a4paper]{ltjbook}
\usepackage{luatexja}
\usepackage{CJKutf8}
\usepackage[left=1.9cm,right=1.9cm,bottom=1.5cm,top=1.5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{amsmath}
\usepackage{ruby}
\usepackage{tikz,pgfplots,makecell,array,aurical,longtable,booktabs,multicol,multirow}
\usetikzlibrary{patterns, mindmap, positioning, automata}
\usepackage{environ}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{textcomp}
\usepackage{hhline}
\usepackage{textcomp}
\usepackage{wasysym}
\usepackage{multicol}
\usepackage{microtype}
\usepackage[table]{xcolor}
\usepackage{ulem}
\usepackage[none]{hyphenat}
\usepackage{xparse}
\usepackage{imakeidx}
\usepackage{setspace}

%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
\newsavebox\ltmcbox
% The following command inhibits a column break after a group letter in the index
% It also swallows the following \\, because the \\ is here before the \nopagebreak.
\newcommand{\dontbreak}[1]{\\\nopagebreak} % Swallow the following \\
\makeindex[name=gen, columns=4, title={漢字 Index}, intoc, columnseprule, options=-s general.ist]
\newcommand{\gindex}[2]{\index[gen]{#1 & #2}}
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
\newcommand\strokesection{} % to make sure we can use this command
\def\strokesection#1\par#2\par{\vspace{5pt}\par
    \parbox[t]{\linewidth}{{#1}\\#2\strut}\par
}

\makeatletter
\patchcmd\LT@array{\tabskip\z@}{\tabskip\fill}{\typeout{OK}}{\typeout{BAD}}
\setlength\LTleft{0pt}\setlength\LTright{0pt}
\makeatletter

\makeindex[name=stroke, columns=4, title={漢字 by Stroke Count}, intoc, columnseprule, options=-s strokes.ist]
\newcommand{\strokeshead}[1]{%
    \rmfamily\textbf{#1 Stroke\ifnum#1>1 s\fi}%
}
\newcommand{\strindex}[2]{\index[stroke]{#1@\strokeshead{#1}!#2}}
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

\newcolumntype{A}{>{\centering\let\newline\\\arraybackslash}X}
\newcolumntype{B}{>{\raggedright\let\newline\\\arraybackslash}X}

\newcommand{\specialc}[2][c]{\setstretch{0.87}\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand{\speciall}[2][c]{\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}}
\newcommand{\specialr}[2][c]{\begin{tabular}[#1]{@{}r@{}}#2\end{tabular}}


\usepackage{graphicx}

\pgfplotsset{compat=newest,compat/show suggested version=false}
\usetikzlibrary{pgfplots.groupplots,matrix,positioning,fit,calc,shapes,patterns,automata,plotmarks}

\setlength{\parindent}{0cm}

\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}

\newcommand{\rye}[2]{\multicolumn{#1}{|l@{}|}{\renewcommand{\arraystretch}{1.2}\begin{tabularx}{0.95\columnwidth}{@{}B@{}}#2\end{tabularx}}\\\hline}

\usepackage{tocloft}
\newcommand{\listofkanji}{List of Kanji}
\newlistof{glyph}{lok}{\listofkanji}
\NewEnviron{glyph}[2]% environment name
{   \refstepcounter{glyph}%
    \addcontentsline{lok}{glyph}{\protect\numberline{\theglyph}{\;}{\;}#1}
    \begin{tabularx}{\columnwidth}{@{}|A|A|A|A|@{}}
        \hhline{|----|}
        \multicolumn{4}{|B|}{\cellcolor{black}{\color{white}\textbf{\large{漢字{\,}\theglyph{:}\;{#1}}}}} \\\hline %row comp
        \hhline{|----|}
        \multicolumn{1}{|c}{\includegraphics[width=0.197\linewidth]{example-image-a}} & \multicolumn{1}{|c}{\includegraphics[width=0.197\linewidth]{example-image-a}} &
        \multicolumn{1}{|c}{\includegraphics[width=0.197\linewidth]{example-image-a}} &
        \multicolumn{1}{|c|}{\includegraphics[width=0.197\linewidth]{example-image-a}}\\\hline
        \multicolumn{4}{|B|}{\renewcommand{\arraystretch}{1.2}
            \begin{tabularx}{0.95\columnwidth}{@{}B@{}}\BODY\end{tabularx}}\\\hline
    \end{tabularx}\renewcommand{\arraystretch}{1}
}

\begin{document}
\begin{multicols}{2}
\begin{glyph}{Anew (更)}{anew}\label{glyph:anew}
The idea of \textit{doing things anew}, be it through \textsuperscript{[1]}\textit{revision}, \textsuperscript{[2]}\textit{reform} or \textsuperscript{[3]}\textit{renewal}, amongst others.\\\hline
A secondary meaning has to do with \textit{staying up late}, or \textit{the day growing late}.
\end{glyph}
\end{multicols}

\end{document}

答案1

添加了类似(更简单)的环境glyphx以消除烦人的 0.197。

b

仅相关的数据包被保留在前言中。

\documentclass[10pt, a4paper]{ltjbook}
\usepackage{luatexja}
\usepackage{CJKutf8}

\usepackage[left=1.9cm,right=1.9cm,bottom=1.5cm,top=1.5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{multicol}
\usepackage{environ}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage{graphicx}

\newcolumntype{A}{>{\centering\let\newline\\\arraybackslash}X}
\newcolumntype{B}{>{\small\raggedright\let\newline\\\arraybackslash}X}  

\setlength{\parindent}{0cm}
\renewcommand{\tabularxcolumn}[1]{>{\small\raggedright}m{#1}}   

\usepackage{tocloft}
\newcommand{\listofkanji}{List of Kanji}
\newlistof{glyph}{lok}{\listofkanji}

\NewEnviron{glyph}[2]% environment name
{\refstepcounter{glyph}%
    \addcontentsline{lok}{glyph}{\protect\numberline{\theglyph}{\;}{\;}#1}
    \begin{tabularx}{\columnwidth}{@{}|A|A|A|A|@{}}
        \hhline{|----|}
        \multicolumn{4}{|B|}{\cellcolor{black}{\color{white}\textbf{\large{漢字{\,}\theglyph{:}\;{#1}}}}} \\\hline %row comp
        \hhline{|----|}
        \multicolumn{1}{|c}{\includegraphics[width=0.197\linewidth]{example-image-a}} & \multicolumn{1}{|c}{\includegraphics[width=0.197\linewidth]{example-image-a}} &
        \multicolumn{1}{|c}{\includegraphics[width=0.197\linewidth]{example-image-a}} &
        \multicolumn{1}{|c|}{\includegraphics[width=0.197\linewidth]{example-image-a}}\\\hline
        \multicolumn{4}{|B|}{\renewcommand{\arraystretch}{1.2}
            \begin{tabularx}{0.95\columnwidth}{@{}B@{}}\BODY\end{tabularx}}\\\hline
    \end{tabularx}\renewcommand{\arraystretch}{1}
}

\NewEnviron{glyphx}[2]% added <<<<<<<<<<<<<<<<<<<<<
{   \refstepcounter{glyph}%
    \addcontentsline{lok}{glyph}{\protect\numberline{\theglyph}{\;}{\;}#1}
    \begin{tabularx}{\columnwidth}{|A|A|A|A|}
        \multicolumn{4}{|l|}{\cellcolor{black}{\color{white}\textbf{\large{漢字{\,}\theglyph{:}\;{#1}}}}} \\\hline %row comp  
        \includegraphics[width=\linewidth]{example-image-a} & 
        \includegraphics[width=\linewidth]{example-image-a} &
        \includegraphics[width=\linewidth]{example-image-a} &
        \includegraphics[width=\linewidth]{example-image-a}\\\hline
        \multicolumn{4}{|l|}{\renewcommand{\arraystretch}{1.2}
        \begin{tabularx}{0.9\columnwidth}{@{}B@{}}\BODY\end{tabularx}}\\\hline
    \end{tabularx}\renewcommand{\arraystretch}{1}
}


\begin{document}
    \begin{multicols}{2}
        \begin{glyph}{Anew (更)}{anew}\label{glyph:anew1}
            The idea of \textit{doing things anew}, be it through \textsuperscript{[1]}\textit{revision}, \textsuperscript{[2]}\textit{reform} or \textsuperscript{[3]}\textit{renewal}, amongst others.\\\hline
            A secondary meaning has to do with \textit{staying up late}, or \textit{the day growing late}.
        \end{glyph}
    \end{multicols}\bigskip

    \begin{multicols}{2}
    \begin{glyphx}{Anew (更)}{anew}\label{glyph:anew2}
        The idea of \textit{doing things anew}, be it through \textsuperscript{[1]}\textit{revision}, \textsuperscript{[2]}\textit{reform} or \textsuperscript{[3]}\textit{renewal}, amongst others.\\ \hline
    A secondary meaning   has to do with \textit{staying up late}, or \textit{the day growing late.} 
    \end{glyphx}
\end{multicols}

    
\end{document}

相关内容