How to format a large annotated codeblock when converting to pdf such that it formats properly, stays at the correct location? How to prevent code flowing off the page? #10523
Unanswered
Gewerd-Strauss
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Edit: If I drastically reduce the codeblock, it still gets rendered in a different place - not at the end, but still not where it should: Within `duflor:::rectangularRange_HSV_iteronce_cpp()`, the
```{Rcpp}
//| label: code_annotation-rectangularRange_HSV_iteronce_cpp
//| lst-label: lst-code_annotation-rectangularRange_HSV_iteronce_cpp
//| lst-cap: Analysis-function used for pixel-analysis via 'duflor.gui'-application.
//| echo: TRUE
//| code-fold: FALSE
//| code-overflow: wrap
//| eval: FALSE
//| cache: FALSE
List rectangularRange_HSV_iteronce_cpp(NumericVector H, // <1>
NumericVector S, // <1>
NumericVector V, // <1>
Nullable<NumericMatrix> upper_bound, // <2>
Nullable<NumericMatrix> lower_bound, // <2>
int image_width,bool check_V) {
int repetitions = H.size();
if (upper_bound.isNotNull()) {
upper_bound_ = static_cast<NumericMatrix>(upper_bound);
num_rows = upper_bound_.rows();
}
for (int j = 0; j < num_rows; j++) {
for (int i = 0; i < repetitions; i++) {
if (check_V) {
// Check bounds and add indices if condition is met
if ((lower_bound_H <= H[i]) && (H[i] <= upper_bound_H)
&& (lower_bound_S <= S[i]) && (S[i] <= upper_bound_S)
&& (lower_bound_V <= V[i]) && (V[i] <= upper_bound_V)) {
int row = (i % image_width) + 1; int col = (i / image_width) + 1;
row_indices.push_back(row); col_indices.push_back(col);
}
} else {
[...] // <3>
}
}
}
return results;
}
```
1. numerical vector of length $Width_{Image} \times Height_{Image}$ containing the respective color compontent of all pixels
2. numerical matrix of dimensions `[3,N]` containing for all `N` spectrums the respective color-component of the boundary triplet in HSV-colorspace
3. Same as above, except that the `V`-component is not part of the logical condition.
Annotated analysis-function used for pixel-analysis via 'duflor.gui'-application.
```{r}
#| label: code_annotation-extract_pixels_HSV
#| echo: TRUE
#| code-fold: FALSE
#| code-overflow: wrap
#| eval: FALSE
#| cache: TRUE
#| lst-label: lst-code_annotation-extract_pixels_HSV
#| lst-cap: Call to `duflor::extract_pixels_HSV()` used internally by the 'duflor.gui'-application.
hsv_results <- extract_pixels_HSV(
pixel.array = im, # <1>
lower_bound = DATA$spectrums$lower_bound, # <2>
upper_bound = DATA$spectrums$upper_bound, # <2>
fast_eval = T, # <3>
bundle_pixelarray = F,
check_value = T, # <4>
use_single_iteration_cpp = T # <3>
)
```
1. cImg-array object containing the color-data of a given image.
2. R-list object containing for each spectrum a vector of HSV-values for the respective bound.
3. These boolean flags combined result in the use of `duflor:::rectangularRange_HSV_iteronce_cpp()` for analysing an image.
4. This boolean flag is set to also consider the `HUE`-component of a pixel when checking it.
### Dataset used for this report
``` |
Beta Was this translation helpful? Give feedback.
0 replies
-
I am afraid you need to play with LaTeX and its rules. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Hello,
I have a subsection of a larger document in which I need to display and annotate a large RCpp-function. This document gets rendered to both html and pdf. For html, this is not an issue.
For PDF, I observe the following issues:
When I convert this to pdf, I get the following doc:
Section of the document where the codeblocks should be positioned:

Session-Info in the appendix prints up to page 13:

End of file, where they end up at page 14ff:

The annotated codeblock is already cut down in number of lines. However, some lines are too large and will run off the screen:

A sample doc can be found at the end.
I have already attempted cutting the large codeblock into multiple smaller ones, e.g.
My intention was to let the different codeblocks be smaller, and thus be able to be more easily positioned after one another by quarto. Unfortunately that didn't help.
How can I resolve this issue?
Thank you,
Sincerely,
~Gw
Complete qmd-doc used to render the pdf-file from which the screenshots above stem.
Beta Was this translation helpful? Give feedback.
All reactions