TransWikia.com

add two horizontal lines between a figure and a table

TeX - LaTeX Asked by Red One on September 14, 2020

I want to add two horizontal lines between each figure and each table but I have to add this command everytime : rule[0.6ex]{textwidth}{0.3mm}

And how can I reduce the red space between the caption and the figure ? Is there a way to put the figure and table in the center without adding begin{center} ... end{center} ? If I can do that, I won’t have the red space anymore I guess.

MWE :

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{graphicx}
usepackage{hyperref}
usepackage{caption}
captionsetup{labelfont=bf,textfont=bf,justification=raggedright,singlelinecheck=false,format=hang}
begin{document}
begin{figure}
caption{Figure-Example.}
begin{center}
rule[0.6ex]{textwidth}{0.3mm}
includegraphics[scale=0.25]{logo.png}
rule[0.6ex]{textwidth}{0.3mm} 
end{center}
textit{Source :} href{google.com}{https://google.com}
end{figure}
%Table :
begin{table}
caption{Table-Example.}
begin{center}
rule[0.6ex]{textwidth}{0.3mm}
begin{tabular}{c|c}
hline
 A & B 
 C & D 
hline
end{tabular}
rule[0.6ex]{textwidth}{0.3mm}
end{center}
textit{Source :} href{google.com}{https://google.com}
label{tab:my_label}
end{table}
end{document}

The result :

enter image description here

One Answer

With newenvironment{name}{begin}{end}, it can be done:

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{graphicx}
usepackage{hyperref}
usepackage{caption}
captionsetup{labelfont=bf,textfont=bf,justification=raggedright,singlelinecheck=false,format=hang}
newenvironment{tablewithrule}[2]{begin{table} caption{#1} centering rule[0.6ex]{textwidth}{0.3mm} caption*{textit{Source}: #2}  }{vspace{1mm}rule[0.6ex]{textwidth}{0.3mm}  end{table}}
begin{document}
begin{tablewithrule}{Table Example}{url{www.google.com}}
begin{tabular}{c|c}
hline
 A & B 
 C & D 
hline
end{tabular}
end{tablewithrule}
end{document}

However, it is not possible to have an argument in the end-part of the order. You've therefore to add it in the begin-part (if you want to have this automatic...).

The distance to the rules can be changed by vspace{}, where you can also enter a negative value, e.g. vspace{-0.4cm}

Edit: you could also work with renewenvironment instead of newenvironment. I however prefer not to meddle with the basic definitions but do new commands based on existing ones.

Answered by Shade on September 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP