0

I do not want my figure/table to be placed in the middle of a paragraph that it split it.

I had tried

\begin{table}[htp!]

and

\begin{table}[h!]

Still not working enter image description here

Second example where the table is auto split the paragraph on a new page.

enter image description here

The MWE:

\documentclass[12pt,oneside]{book}

 \usepackage{showframe}
 \renewcommand\ShowFrameLinethickness{0.15pt}
 \renewcommand*\ShowFrameColor{\color{red}}

\usepackage{makecell,siunitx}
\usepackage{booktabs}
\usepackage{graphicx}

\usepackage{parskip} % <================================================
\usepackage{caption} % <================================================


\begin{document} 

"When entering the door at Lou's, two things are immediately noticeable: the place is rarely empty and seems to consist of a maze of rooms. The first room, through the door, is the main part of the restaurant. There is another, rarely used, dining room off to the right. It was added during the oil well boom of the seventies. Through the main dining room is yet another room; it guards the door leading into the kitchen. This room contains the most coveted table in the place. The highest tribute Lou can bestow on anyone is to allow them access to seats at this table. This table is the family table; it is reserved for Lou's, and her daughter Karen's, immediate family and treasured friends."

"Like his twisted feathers, his many scars, the reliable old owl chose the gnarled, weather-beaten, but solid branch often - it being a companion to the wise alone with the night and the last branch to creak in the heaviest wind. He often came to survey the fields and the clouds before his hunt, to listen to the steady sound of the stream passing through reeds under the bridge, while combing his feathers for the unwanteds - whatever they might be."

"Looking back on a childhood filled with events and memories, I find it rather difficult to pick one that leaves me with the fabled "warm and fuzzy feelings." As the daughter of an Air Force major, I had the pleasure of traveling across America in many moving trips. I have visited the monstrous trees of the Sequoia National Forest, stood on the edge of the Grand Canyon and have jumped on the beds at Caesar's Palace in Lake Tahoe."

"When entering the door at Lou's, two things are immediately noticeable: the place is rarely empty and seems to consist of a maze of rooms. The first room, through the door, is the main part of the restaurant. There is another, rarely used, dining room off to the right. It was added during the oil well boom of the seventies. Through the main dining room is yet another room; it guards the door leading into the kitchen. This room contains the most coveted table in the place. The highest tribute Lou can bestow on anyone is to allow them access to seats at this table. This table is the family table; it is reserved for Lou's, and her daughter Karen's, immediate family and treasured friends."


\begin{figure}[h!]
    \centering
    \includegraphics[scale=0.2]{name/PilotStudy.png}
    \caption{Test}
    \label{fig:Test}
\end{figure}



"The day I picked my dog up from the pound was one of the happiest days of both of our lives. I had gone to the pound just a week earlier with the idea that I would just "look" at a puppy. Of course, you can no more just look at those squiggling little faces so filled with hope and joy than you can stop the sun from setting in the evening. I knew within minutes of walking in the door that I would get a puppy… but it wasn't until I saw him that I knew I had found my puppy."

"Looking for houses was supposed to be a fun and exciting process. Unfortunately, none of the ones that we saw seemed to match the specifications that we had established. They were too small, too impersonal, too close to the neighbors. After days of finding nothing even close, we began to wonder: was there really a perfect house out there for us?"

Below is a pdf link to personal statements and application essays representing strong efforts by students applying for both undergraduate and graduate opportunities. These ten essays have one thing in common: They were all written by students under the constraint of the essay being 1-2 pages due to the target program’s explicit instructions. In such circumstances, writers must attend carefully to the essay prompt (sometimes as simple as “Write a one-page summary of your reasons for wanting to pursue graduate study”) and recognize that evaluators tend to judge these essays on the same fundamental principles, as follows:

\begin{table}[htp!]
\centering
\begin{tabular}{%
  l
  S[table-format=2.2,table-space-text-post=\%]
  S[table-format=3.2,,table-space-text-post=\%]
}
\toprule
    & \multicolumn{2}{c}{\thead{\makebox[0pt]{\textbf{Descriptive Analysis 1}}}}\\ 
     \cmidrule{2-3}
& \textbf{MM}
& \textbf{CM} \\
\midrule
N       & {10}  &  {10}      \\
    Mean    & 91.45\%  & 8.55\% \\
    Median  & 94.74\%  & 5.26\% \\
\bottomrule
\end{tabular}
\captionof{table}{the wantet title of table} % <========================
\label{tab:title} % <===================================================
\end{table}

"Billy Ray's Pawn Shop and Lawn Mower Repair looked like a burial ground for country auction rejects. The blazing, red, diesel fuel tanks beamed in front of the station, looking like cheap lipstick against the pallid, wrinkled texture of the parking lot sand. The yard, not much larger than the end zone at General G. Patton High School on the north end of town, was framed with a rusted metallic hedge of lawn mowers, banana seat bicycles, and corroded oil drums. It wasn't a calico frame of rusted parts, but rather an orchestra of unwanted machinery that Billy Ray had arranged into sections. The yellow-tanked mowers rested silently at the right of the diesel fuel. Once red, now faded orange, mowers stood at attention to the left. The oil barrels, jaded and pierced with holes, bellared like chimes when the wind was right. The bikes rested sporadically throughout the lot. In the middle of it all was the office, a faded, steel roof supported by cheap two-by-fours and zebra paneling. Billy Ray was at home, usually, five blocks east of town on Kennel Road."

\begin{center}
\begin{tabular}{%
  l
  S[table-format=2.2,table-space-text-post=\%]
  S[table-format=3.2,,table-space-text-post=\%]
}
\toprule
    & \multicolumn{2}{c}{\thead{\makebox[0pt]{\textbf{Descriptive Analysis 1}}}}\\ 
     \cmidrule{2-3}
& \textbf{MM}
& \textbf{CM} \\
\midrule
N       & {10}  &  {10}      \\
    Mean    & 91.45\%  & 8.55\% \\
    Median  & 94.74\%  & 5.26\% \\
\bottomrule
\end{tabular}
\captionof{figure}{the wantet title of table} % <========================
\label{tab:title} % <===================================================
\end{center}


"When entering the door at Lou's, two things are immediately noticeable: the place is rarely empty and seems to consist of a maze of rooms. The first room, through the door, is the main part of the restaurant. There is another, rarely used, dining room off to the right. It was added during the oil well boom of the seventies. Through the main dining room is yet another room; it guards the door leading into the kitchen. This room contains the most coveted table in the place. The highest tribute Lou can bestow on anyone is to allow them access to seats at this table. This table is the family table; it is reserved for Lou's, and her daughter Karen's, immediate family and treasured friends.

\end{document}
aan
  • 2,663
  • If you do not want your image and tabular to float (move away from where ist was mentioned in the code), do not use floating environments such as figure and table. You can instead adapt the approach you already used in your second tabular. – leandriis Sep 05 '19 at 09:20
  • you can use position specifier H defined by package `float. But consequences of this approach -- bad formatting of document -- is than up to you. I wouldn't do that. – Zarko Sep 05 '19 at 09:27
  • unrelated but "when entering.. should be \`when entering ....don't use the straight"` in TeX text. – David Carlisle Sep 05 '19 at 09:39
  • @Zarko, can you explain more on using position specifier H? – aan Sep 05 '19 at 10:46
  • @leandriis, i used the \begin{center} and \captionof{figure}{blabla}. There is compile warming: Package caption Warning: The option 'hypcap=true' will be ignored for this particular \caption on inut line... – aan Sep 05 '19 at 11:29
  • This is not reproducible with the MWE you provided so far. Do you use the hyperref package in your actual document? If so, please also include it in the example in your question. – leandriis Sep 05 '19 at 11:42
  • Regarding the warning see also here: Issue with capt-of package and – leandriis Sep 05 '19 at 11:44
  • @leandriis. thanks. I added \usepackage[hypcap=false]{caption} to elimate the warning. – aan Sep 05 '19 at 11:54
  • 1
    This is closely related, possibly a duplicate of https://tex.stackexchange.com/questions/246155/how-to-place-floats-between-paragraphs/246315#246315 – David Carlisle Sep 05 '19 at 13:32

2 Answers2

2

Here is an example of use H specifier for image positioning in document. It clearly and loudly show why is your intention against good typography and why you should avoid as much as possible:

\documentclass[12pt,oneside]{book}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\usepackage{siunitx}
\usepackage{booktabs, makecell}
\usepackage{float}  % <--- for "H" float positioning specification 
\usepackage{graphicx}
\usepackage{caption} 

\usepackage{parskip}

\begin{document}
\lipsum[1-2]
\begin{figure}[H] % for comparison replace "H" with "htb
\includegraphics[width=\linewidth]{example-image-duck}
    \caption{Test}
    \label{fig:Test}
\end{figure}
\lipsum[3-4]
\begin{figure}[H] % for comparison replace "H" with "htb
\includegraphics[width=\linewidth]{example-image-duck}
    \caption{Test}
    \label{fig:Test}
\end{figure}
\lipsum[5-7]
\end{document}

For comparison replace [H] with [htb]. Difference is evident and huge. But it is up to you what you like to have. I would stick with [htb].

BTW, one of the main advantage of LaTeX over Word is the ability to automatic move figures and tables so, that you obtain beautiful document.

Zarko
  • 296,517
  • thanks. May i know what is the different using H and [htb]? I couldn't see the difference – aan Sep 05 '19 at 16:14
  • @ann, do you test both cases? Isn't big difference between them? – Zarko Sep 05 '19 at 16:23
  • Thanks. I saw the difference. H did not split the paragraph, but leave a large space in a page. htb will split the paragraph. The best solution will be using \usepackage{caption} – aan Sep 05 '19 at 21:57
  • @aan, what caption have to do with your problem? Sorry, I don't understand you. – Zarko Sep 05 '19 at 22:00
  • Sorry, I mean i will use \begin{center}, \captionof{}{}, \end{center} which does not split the paragraph and also does not leave a large space in a page – aan Sep 05 '19 at 22:05
  • @ann, do you test this with my MWE? You will see that your claims not hold. You will obtain even worse result (captions on the next page, etc). Well, you can do what you wish, but after that don't say that we were not warning you about consequences. – Zarko Sep 05 '19 at 22:13
  • thanks. I just tried yours MWE replace with \begin{center}, \captionof{}{}, \end{center}. The figure does go to first page, but the label of the figure goes to second page. Very difficult.....because of the figure size? – aan Sep 05 '19 at 22:20
  • @ann, because center environment can be broken over pages. I strongly encourage you to read some introductory text about LaTeX. For example "No so short introduction to LaTeX" (you can simply find with Google) – Zarko Sep 05 '19 at 22:43
-1

Other way, in the same though of Zarko, is in use of minipage, makebox and the caption package. You will not use the figure environment, and the captionof command of caption will do all is needed about it, for figure and table too.

\documentclass[12pt,oneside]{book}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum} 
\usepackage{graphicx}
\usepackage{caption} 

%\captionsetup{figurewithin=} --use it if figure count isn't continuously
%\captionsetup{figurewithin=,tablewithin=} --uncomment if figure and table 
%counters isn't continuously
%see the caption documentation to learn more about captionsetup

\begin{document}
\lipsum[1-2]

\noindent%
\begin{minipage}{\linewidth}%
\makebox[\linewidth]{%
\includegraphics[width=\linewidth]{example-image}}
    \captionof{figure}{Test}
    \label{fig:Test}
\end{minipage}

\lipsum[3-4]

\begin{minipage}{\linewidth}%
\makebox[\linewidth]{%
    \begin{tabular}{lcc}
    \hline
    Test & A & B \\
    Test & C & D \\
    \hline
    \end{tabular}}
    \captionof{table}{Test}
    \label{tabl:Test}
\end{minipage}

\lipsum[5-7]
\end{document}

Page with figure

Page with tabular

Jean Pimenta
  • 617
  • 5
  • 9
  • Could you please explain what the purpose of \makebox[\linewidth]{ is? – leandriis Sep 05 '19 at 13:19
  • To keep centered what's inside it. – Jean Pimenta Sep 05 '19 at 13:22
  • Why not use \centering instead? – leandriis Sep 05 '19 at 13:27
  • 1
    The first makebox does nothing here as the minipage and the image are already linewidth wide so centering does nothing. Also you are missing a \noindent before the second minipage, as posted it will be indented. Please always (in questions and answers) use example-image so that people can run the test document, currently no one can run the document as they do not have the image. – David Carlisle Sep 05 '19 at 13:27
  • I don't know but here, if I not use makebox, my table or image will be not centered. – Jean Pimenta Sep 05 '19 at 13:30
  • As already mentioned before, you can use \begin{minipage}{\linewidth} \centering \begin{tabular} to horizontally center the table. The same command can be used before \includegraphics to horizontally center an image . This is however not needed if the image is already as wide as the textwidth. – leandriis Sep 05 '19 at 13:34
  • I tried this MWE and include my own picture, it also leave a large blank page at the bottom, the figure located in next new page. The only advantage is that does not split the paragraph. – aan Sep 05 '19 at 22:11