在我的论文中,所有使用 tabularx 包的表格都自动编号为零。例如,我有第 4 章,它以 6 个表格开头,编号为 4.0... 我以为我只需在每个表格前使用 \setcounter{table}{value} 就可以解决这个问题,而且它有效。但现在我发现,虽然文档中的编号是正确的,但在我的“表格列表”(我正在使用的论文模板的一部分)中,编号仍然是错误的。所以我想我必须从源头上解决实际问题,但我不知道如何解决。
一个显而易见的解决方案就是废除 tabularx,但我需要这个包来生成这种图像定位:
这是我的代码:
\documentclass[11pt, oneside]{Thesis} % The default font size and one-sided printing (no margin offsets)
\graphicspath{{./Pictures/}} % Specifies the directory where pictures are stored
\usepackage[T1]{fontenc}
\usepackage{mathtools} % loads »amsmath«
\usepackage{amsmath}
\usepackage{physics}
\usepackage{float}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage[english]{babel}
\usepackage[table]{xcolor}
\usepackage{tabularx}
%\usepackage{showframe} % for demo
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{lua-visual-debug}
\usepackage{makecell}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[square, numbers, comma, sort&compress]{natbib}
\usepackage{booktabs}
%\usepackage[table,xcdraw]{xcolor}
\hypersetup{urlcolor=blue, colorlinks=true} % Colors hyperlinks in blue - change to black if annoying
\title{\ttitle} % Defines the thesis title - don't touch this
\begin{document}
%%%%%%%%%%%%%%%%%%% EXAMPLE OF A TABLE WITH TABULARX %%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[h]
\centering
\hspace*{-2cm}\makebox[\linewidth][c]{%
\begin{tabularx}{1.2\textwidth}{c*{2}{>{\centering\arraybackslash}X}@{}}
\multirow{2}{*}{
\begin{subfigure}{3cm}
\vspace{-1cm}
\includegraphics[height=12cm]{example-image}
\end{subfigure}}
& \begin{subfigure}{\hsize}
\caption*{k-$\varepsilon$ RNG}
\includegraphics[width=\hsize,height=8cm]{example-image}
\medskip
\end{subfigure}
& \begin{subfigure}{\hsize}
\caption*{k-$\varepsilon$ Realizable}
\includegraphics[width=\hsize,height=8cm]{example-image}
\medskip
\end{subfigure} \\
& \begin{subfigure}{\hsize}
\caption*{k-$\omega$ SST}
\includegraphics[width=\hsize,height=8cm]{example-image}
\end{subfigure}
& \begin{subfigure}{\hsize}
\caption*{LES}
\includegraphics[width=\hsize,height=8cm]{example-image}
\end{subfigure}
\end{tabularx}}
\caption{Turbulence models comparison: Turbulent kinetic energy [J/kg] and Subgrid turbulent viscosity ratio [kg/m.s] for LES model}
\label{kinetic}
\end{table}
%%%%%%%%%%%%%%%%%%%% EXAMPLE OF A TABLE WITHOUT TABULARX %%%%%%%%%%%%%%%%%%%%
\begin{table}[htp]
\centering
\hspace*{-1.5cm}
\makebox[\columnwidth][c]{%
\begin{minipage}{1.35\linewidth}
\centering
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{In-plane velocity vectors [m/s] - Normal profile}
\medskip
\end{subfigure}\hfill
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{In-plane velocity vectors [m/s] - Inverted profile}
\medskip
\end{subfigure} \\
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{In-plane velocity vectors [m/s] - Normal profile close-up}
\medskip
\end{subfigure}\hfill
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{In-plane velocity vectors [m/s] - Inverted profile close-up}
\medskip
\end{subfigure} \\
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Radial velocity contours [m/s] - Normal profile close-up}
\medskip
\end{subfigure}\hfill
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Radial velocity contours [m/s] - Inverted profile close-up}
\medskip
\end{subfigure} \\
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-imagez}
\caption{Subgrid turbulent viscosity ratio [kg/m.s] - Normal profile close-up}
\medskip
\end{subfigure}\hfill
\begin{subfigure}[t]{.49\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Subgrid turbulent viscosity ratio [kg/m.s] - Inverted profile close-up}
\medskip
\end{subfigure} \\
\end{minipage}}
%OVERALL CAPTION AND LABEL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\caption{Comparison of 0,2mm normal and inverted profiles}
\label{0.2mm_comparison}
\end{table}
\end{document}
答案1
从(几乎)相同的问题(不久前)我们知道,这与编号tabularx
冲突。因此,坚持在这样的应用程序中使用它毫无意义。相反,最好使用普通的 并手动计算列宽(请参阅下面的 MWE)。subcaption
caption
tabular
multirow
适用于所有类型的表,因此对于它的使用,没有必要坚持使用tabularx
。相反,如果要直接使用multirow
,我更喜欢使用\multirowcell{<number of lines>}{...}
来自包makecell
。此功能 makecell
基于multirow
包。
再次介绍如何使表格比文本更宽。专用包是changepage
。这里我使用选项strict
和版本\adjustwidth*
,将表格宽度突出到外边距。有关详细信息,请参阅此包的文档。
代码:
\documentclass[11pt,oneside]{book} % The default font size and
% one-sided printing (no margin offsets)
%\graphicspath{{./Pictures/}} % Specifies the directory where pictures are stored
\usepackage[T1]{fontenc}
%\usepackage{physics}
%\usepackage{float}
%\usepackage{adjustbox}
%\usepackage[english]{babel}
\usepackage{mathtools} % loads »amsmath«
\usepackage{calc}% added for column width calculation
\usepackage[strict]{changepage}% added for column width calculation
\usepackage{booktabs,makecell,multirow}% for tables
\usepackage[svgnames,table]{xcolor}% added color names
%\usepackage{showframe} % for demo
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{ragged2e}
%\usepackage{lua-visual-debug}
%\usepackage{placeins}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
%\usepackage[square, numbers, comma, sort&compress]{natbib}
%\hypersetup{urlcolor=blue, colorlinks=true} % Colors hyperlinks in blue - change to black if annoying
%\title{\ttitle} % Defines the thesis title - don't touch this
\begin{document}
\begin{table}[h]
\begin{adjustwidth*}{}{-0.2\hsize}
%\hspace*{-2cm}\makebox[\linewidth][c]{% don't doing this,
% in such cases is better to use {adjustwidth*}
% from package ˙changepage`
\begin{tabular}{@{}p{30mm}*{2}{p{0.5\linewidth-15mm}}@{}}
% centering of columns is not necessary,
% figures take full width of column!
\multirowcell{2}{
\includegraphics[width=\hsize,height=12cm]{example-image} }
& \begin{subfigure}{\hsize}
\caption*{k-$\varepsilon$ RNG}
\includegraphics[width=\hsize,height=8cm]{example-image}
\end{subfigure}
& \begin{subfigure}{\hsize}
\caption*{k-$\varepsilon$ Realizable}
\includegraphics[width=\hsize,height=8cm]{example-image}
\end{subfigure}\bigskip \\
& \begin{subfigure}{\hsize}
\caption*{k-$\omega$ SST}
\includegraphics[width=\hsize,height=8cm]{example-image}
\end{subfigure}
& \begin{subfigure}{\hsize}
\caption*{LES}
\includegraphics[width=\hsize,height=8cm]{example-image}
\end{subfigure}
\end{tabular}
\caption{Turbulence models comparison: Turbulent kinetic energy [J/kg] and Subgrid turbulent viscosity ratio [kg/m.s] for LES model}
\label{kinetic}
\end{adjustwidth*}
\end{table}
\end{document}
从代码中可以看出,我注释了所有与显示图形无关的包。我还使用了 documentclassbook
来代替Thesis
(我没有安装)。代码中还包含一些注释,以作说明。
答案2
您既不需要tabularx
也不需要multirow
。不清楚为什么要将内容推到左侧并希望使用超过默认文本宽度的内容,但我没有更改这一点。
您只需要一个用于四幅图像的表格;我对左边的图像使用了另一个表格,只是为了获得垂直居中(还有其他几种方法)。
注意二嵌套\makebox
命令:第一个是让 TeX 忽略内部命令的宽度,它是1.2\textwidth
用[s]
可选参数设置的。
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{siunitx}
\newlength{\mylength}
\begin{document}
%%%%%%%%%%%%%%%%%%% EXAMPLE OF A TABLE WITH TABULARX %%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[htp]
\centering
\setlength{\mylength}{1.2\textwidth}
\addtolength{\mylength}{-3cm} % the side figure
\addtolength{\mylength}{-4\tabcolsep} % the space between the columns
\hspace*{-2cm}\makebox[\textwidth]{\makebox[1.2\textwidth][s]{%
\begin{tabular}{@{}c@{}}
\includegraphics[width=3cm,height=12cm]{example-image}
\end{tabular}\hfill
\begin{tabular}{@{}cc@{}}
\begin{subfigure}{0.5\mylength}
\caption*{k-$\varepsilon$ RNG}
\includegraphics[width=0.5\mylength,height=8cm]{example-image}
\end{subfigure}
& \begin{subfigure}{0.5\mylength}
\caption*{k-$\varepsilon$ Realizable}
\includegraphics[width=0.5\mylength,height=8cm]{example-image}
\end{subfigure} \\ \\ % space out the two rows
\begin{subfigure}{0.5\mylength}
\caption*{k-$\omega$ SST}
\includegraphics[width=0.5\mylength,height=8cm]{example-image}
\end{subfigure}
& \begin{subfigure}{0.5\mylength}
\caption*{LES}
\includegraphics[width=0.5\mylength,height=8cm]{example-image}
\end{subfigure}
\end{tabular}%
}}
\caption{Turbulence models comparison: Turbulent kinetic energy (\si{J/kg}) and Subgrid turbulent
viscosity ratio (\si{kg/m.s}) for LES model} \label{kinetic}
\end{table}
\end{document}
siunitx
请注意单位和符号周围的括号的使用(方括号是不正确的,因为它们表示维度,而不是单位)。